26 #define TIME_FNS_NEED_LOCKS
36 correct_tm(
int islocal,
const time_t *timep,
struct tm *resultbuf,
37 struct tm *r,
char **err_out)
41 if (PREDICT_LIKELY(r)) {
44 if (r->tm_year > 8099) {
53 }
else if (r->tm_year < (1-1900)) {
54 r->tm_year = (1-1900);
80 outcome =
"Rounding up to 1970";
82 }
else if (*timep >= INT32_MAX) {
94 outcome =
"Rounding down to 2037";
103 memset(resultbuf, 0,
sizeof(
struct tm));
104 outcome=
"can't recover";
108 tor_asprintf(err_out,
"%s(%"PRId64
") failed with error %s: %s",
109 islocal?
"localtime":
"gmtime",
110 timep?((int64_t)*timep):0,
123 #ifdef HAVE_LOCALTIME_R
128 r = localtime_r(timep, result);
129 return correct_tm(1, timep, result, r, err_out);
131 #elif defined(TIME_FNS_NEED_LOCKS)
140 r = localtime(timep);
142 memcpy(result, r,
sizeof(
struct tm));
144 return correct_tm(1, timep, result, r, err_out);
152 r = localtime(timep);
154 memcpy(result, r,
sizeof(
struct tm));
155 return correct_tm(1, timep, result, r, err_out);
171 r = gmtime_r(timep, result);
172 return correct_tm(0, timep, result, r, err_out);
174 #elif defined(TIME_FNS_NEED_LOCKS)
185 memcpy(result, r,
sizeof(
struct tm));
187 return correct_tm(0, timep, result, r, err_out);
197 memcpy(result, r,
sizeof(
struct tm));
198 return correct_tm(0, timep, result, r, err_out);
Utility macros to handle different features and behavior in different compilers.
tor_mutex_t * tor_mutex_new(void)
void tor_mutex_release(tor_mutex_t *m)
void tor_mutex_acquire(tor_mutex_t *m)
int tor_asprintf(char **strp, const char *fmt,...)
Definitions for timing-related constants.
struct tm * tor_localtime_r_msg(const time_t *timep, struct tm *result, char **err_out)
struct tm * tor_gmtime_r_msg(const time_t *timep, struct tm *result, char **err_out)
static struct tm * correct_tm(int islocal, const time_t *timep, struct tm *resultbuf, struct tm *r, char **err_out)
Integer definitions used throughout Tor.