From 1bf4198e11f8d62effdc8b0115fcca22000731d4 Mon Sep 17 00:00:00 2001 From: Martin Stjernholm <mast@lysator.liu.se> Date: Sun, 2 Jul 2006 02:00:06 +0200 Subject: [PATCH] Use thread safe variant of gmtime(3) if available. Rev: src/builtin_functions.c:1.618 Rev: src/configure.in:1.967 --- src/builtin_functions.c | 13 +++++++++++-- src/configure.in | 9 +++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/builtin_functions.c b/src/builtin_functions.c index c9428c387d..d934cbd355 100644 --- a/src/builtin_functions.c +++ b/src/builtin_functions.c @@ -2,7 +2,7 @@ || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. -|| $Id: builtin_functions.c,v 1.617 2006/03/25 12:43:27 grubba Exp $ +|| $Id: builtin_functions.c,v 1.618 2006/07/02 00:00:06 mast Exp $ */ #include "global.h" @@ -4820,7 +4820,7 @@ static void encode_struct_tm(struct tm *tm) } #endif -#ifdef HAVE_GMTIME +#if defined (HAVE_GMTIME) || defined (HAVE_GMTIME_R) || defined (HAVE_GMTIME_S) /*! @decl mapping(string:int) gmtime(int timestamp) *! *! Convert seconds since 00:00:00 UTC, Jan 1, 1970 into components. @@ -4833,6 +4833,9 @@ static void encode_struct_tm(struct tm *tm) */ PMOD_EXPORT void f_gmtime(INT32 args) { +#if defined (HAVE_GMTIME_R) || defined (HAVE_GMTIME_S) + struct tm tm_s; +#endif struct tm *tm; INT_TYPE tt; time_t t; @@ -4840,7 +4843,13 @@ PMOD_EXPORT void f_gmtime(INT32 args) get_all_args("gmtime", args, "%i", &tt); t = tt; +#ifdef HAVE_GMTIME_R + tm = gmtime_r (&t, &tm_s); +#elif defined (HAVE_GMTIME_S) + if (!gmtime_s (&tm_s, &t)) tm = &tm_s; +#else tm = gmtime(&t); +#endif if (!tm) Pike_error ("gmtime() on this system cannot handle " "the timestamp %ld.\n", (long) t); pop_n_elems(args); diff --git a/src/configure.in b/src/configure.in index e7163353ea..6697d783a5 100644 --- a/src/configure.in +++ b/src/configure.in @@ -1,4 +1,4 @@ -AC_REVISION("$Id: configure.in,v 1.966 2006/07/01 23:58:03 mast Exp $") +AC_REVISION("$Id: configure.in,v 1.967 2006/07/02 00:00:06 mast Exp $") AC_INIT(interpret.c) AC_CONFIG_HEADER(machine.h) @@ -2255,7 +2255,7 @@ if test "x$PIKE_PATH_TRANSLATE" = "x"; then # MinGW system. cat <<\EOF #!/bin/sh -# Automatically generated by $Id: configure.in,v 1.966 2006/07/01 23:58:03 mast Exp $. +# Automatically generated by $Id: configure.in,v 1.967 2006/07/02 00:00:06 mast Exp $. # MinGW-version. Do NOT edit. posix_name="`cat`" posix_prefix="/" @@ -2293,7 +2293,7 @@ EOF # Native POSIX system. cat <<\EOF #!/bin/sh -# Automatically generated by $Id: configure.in,v 1.966 2006/07/01 23:58:03 mast Exp $. +# Automatically generated by $Id: configure.in,v 1.967 2006/07/02 00:00:06 mast Exp $. # POSIX-version. Do NOT edit. cat EOF @@ -2302,7 +2302,7 @@ else # rntcl-style cat <<\EOF #!/bin/sh -# Automatically generated by $Id: configure.in,v 1.966 2006/07/01 23:58:03 mast Exp $. +# Automatically generated by $Id: configure.in,v 1.967 2006/07/02 00:00:06 mast Exp $. # RNTCL-version. Do NOT edit. sed -e "$PIKE_PATH_TRANSLATE" EOF @@ -4019,6 +4019,7 @@ AC_CHECK_FUNCS( \ localtime \ gmtime \ gmtime_r \ + gmtime_s \ memchr \ mktime \ perror \ -- GitLab