Prefer the reentrant versions of gmtime and localtime
This commit is contained in:
parent
fc9f9231cf
commit
e057b9eea9
@ -851,6 +851,12 @@ anc_inspect_ipv6_pktinfo(int level, int type, VALUE data, VALUE ret)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_GMTIME_R
|
||||||
|
# define LOCALTIME(time, tm) localtime_r(&(time), &(tm))
|
||||||
|
#else
|
||||||
|
# define LOCALTIME(time, tm) ((tm) = *localtime(&(time)))
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(SCM_TIMESTAMP) /* GNU/Linux, FreeBSD, NetBSD, OpenBSD, MacOS X, Solaris */
|
#if defined(SCM_TIMESTAMP) /* GNU/Linux, FreeBSD, NetBSD, OpenBSD, MacOS X, Solaris */
|
||||||
static int
|
static int
|
||||||
inspect_timeval_as_abstime(int level, int optname, VALUE data, VALUE ret)
|
inspect_timeval_as_abstime(int level, int optname, VALUE data, VALUE ret)
|
||||||
@ -862,7 +868,7 @@ inspect_timeval_as_abstime(int level, int optname, VALUE data, VALUE ret)
|
|||||||
char buf[32];
|
char buf[32];
|
||||||
memcpy((char*)&tv, RSTRING_PTR(data), sizeof(tv));
|
memcpy((char*)&tv, RSTRING_PTR(data), sizeof(tv));
|
||||||
time = tv.tv_sec;
|
time = tv.tv_sec;
|
||||||
tm = *localtime(&time);
|
LOCALTIME(time, tm);
|
||||||
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
|
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
|
||||||
rb_str_catf(ret, " %s.%06ld", buf, (long)tv.tv_usec);
|
rb_str_catf(ret, " %s.%06ld", buf, (long)tv.tv_usec);
|
||||||
return 1;
|
return 1;
|
||||||
@ -882,7 +888,7 @@ inspect_timespec_as_abstime(int level, int optname, VALUE data, VALUE ret)
|
|||||||
struct tm tm;
|
struct tm tm;
|
||||||
char buf[32];
|
char buf[32];
|
||||||
memcpy((char*)&ts, RSTRING_PTR(data), sizeof(ts));
|
memcpy((char*)&ts, RSTRING_PTR(data), sizeof(ts));
|
||||||
tm = *localtime(&ts.tv_sec);
|
LOCALTIME(ts.tv_sec, tm);
|
||||||
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
|
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
|
||||||
rb_str_catf(ret, " %s.%09ld", buf, (long)ts.tv_nsec);
|
rb_str_catf(ret, " %s.%09ld", buf, (long)ts.tv_nsec);
|
||||||
return 1;
|
return 1;
|
||||||
@ -906,7 +912,7 @@ inspect_bintime_as_abstime(int level, int optname, VALUE data, VALUE ret)
|
|||||||
uint64_t res_h, res_l;
|
uint64_t res_h, res_l;
|
||||||
char buf[32];
|
char buf[32];
|
||||||
memcpy((char*)&bt, RSTRING_PTR(data), sizeof(bt));
|
memcpy((char*)&bt, RSTRING_PTR(data), sizeof(bt));
|
||||||
tm = *localtime(&bt.sec);
|
LOCALTIME(bt.sec, tm);
|
||||||
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
|
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);
|
||||||
|
|
||||||
/* res_h = frac * 10**19 / 2**64 */
|
/* res_h = frac * 10**19 / 2**64 */
|
||||||
|
4
time.c
4
time.c
@ -1169,7 +1169,11 @@ init_leap_second_info(void)
|
|||||||
struct vtm vtm;
|
struct vtm vtm;
|
||||||
wideval_t timew;
|
wideval_t timew;
|
||||||
now = time(NULL);
|
now = time(NULL);
|
||||||
|
#ifdef HAVE_GMTIME_R
|
||||||
|
gmtime_r(&now, &result);
|
||||||
|
#else
|
||||||
gmtime(&now);
|
gmtime(&now);
|
||||||
|
#endif
|
||||||
tm = gmtime_with_leapsecond(&now, &result);
|
tm = gmtime_with_leapsecond(&now, &result);
|
||||||
if (!tm) return;
|
if (!tm) return;
|
||||||
this_year = tm->tm_year;
|
this_year = tm->tm_year;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user