diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-10-14 20:09:37 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-10-14 23:44:15 +0900 |
commit | e057b9eea9021046a43dd59f45fe0cf34d69e8cb (patch) | |
tree | d810f3e016ead407495fb3f9698eb46a6e4f2f43 /ext | |
parent | fc9f9231cf6ce911df37256faf22e6e8e23cb988 (diff) | |
download | ruby-e057b9eea9021046a43dd59f45fe0cf34d69e8cb.tar.gz |
Prefer the reentrant versions of gmtime and localtime
Diffstat (limited to 'ext')
-rw-r--r-- | ext/socket/ancdata.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/ext/socket/ancdata.c b/ext/socket/ancdata.c index 4ec3f3d0a8..aa62cab0ec 100644 --- a/ext/socket/ancdata.c +++ b/ext/socket/ancdata.c @@ -851,6 +851,12 @@ anc_inspect_ipv6_pktinfo(int level, int type, VALUE data, VALUE ret) } #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 */ static int 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]; memcpy((char*)&tv, RSTRING_PTR(data), sizeof(tv)); time = tv.tv_sec; - tm = *localtime(&time); + LOCALTIME(time, tm); strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm); rb_str_catf(ret, " %s.%06ld", buf, (long)tv.tv_usec); return 1; @@ -882,7 +888,7 @@ inspect_timespec_as_abstime(int level, int optname, VALUE data, VALUE ret) struct tm tm; char buf[32]; 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); rb_str_catf(ret, " %s.%09ld", buf, (long)ts.tv_nsec); return 1; @@ -906,7 +912,7 @@ inspect_bintime_as_abstime(int level, int optname, VALUE data, VALUE ret) uint64_t res_h, res_l; char buf[32]; 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); /* res_h = frac * 10**19 / 2**64 */ |