Modernize MT_safe_localtime. r=kaie.
authorWan-Teh Chang <wtc@google.com>
Mon, 14 Nov 2016 13:54:40 -0800
changeset 4705 1f5630faef26ec49b472006f20dd35bd5957c211
parent 4700 1c573a95fb8987bc4e8e4786da93033dbd43fc5b
child 4706 56a754a74f38c0f10adbc41bc3abaf483a45b3bf
push id229
push userwtc@google.com
push dateMon, 14 Nov 2016 21:56:07 +0000
reviewerskaie
Modernize MT_safe_localtime. r=kaie. Define HAVE_POINTER_LOCALTIME_R for Linux and Mac OS X. Add a definition of MT_safe_localtime() based on localtime_s() for Visual C++.
configure
configure.in
pr/src/misc/prtime.c
--- a/configure
+++ b/configure
@@ -6519,16 +6519,18 @@ fi
     $as_echo "#define XP_UNIX 1" >>confdefs.h
 
     $as_echo "#define DARWIN 1" >>confdefs.h
 
     $as_echo "#define HAVE_BSD_FLOCK 1" >>confdefs.h
 
     $as_echo "#define HAVE_SOCKLEN_T 1" >>confdefs.h
 
+    $as_echo "#define HAVE_POINTER_LOCALTIME_R 1" >>confdefs.h
+
     AS='$(CC) -x assembler-with-cpp'
     CFLAGS="$CFLAGS -Wall -fno-common"
     case "${target_cpu}" in
         arm*)
             CPU_ARCH=arm
             ;;
         i*86*|x86_64)
             if test -n "$USE_64"; then
@@ -6970,16 +6972,18 @@ tools are selected during the Xcode/Deve
         IMPL_STRATEGY=_PTH
     fi
     $as_echo "#define XP_UNIX 1" >>confdefs.h
 
     $as_echo "#define _GNU_SOURCE 1" >>confdefs.h
 
     $as_echo "#define HAVE_FCNTL_FILE_LOCKING 1" >>confdefs.h
 
+    $as_echo "#define HAVE_POINTER_LOCALTIME_R 1" >>confdefs.h
+
     case "${target}" in
     *-android*|*-linuxandroid*)
         OS_TARGET=Android
         $as_echo "#define LINUX 1" >>confdefs.h
 
         ;;
     *-linux*)
         $as_echo "#define LINUX 1" >>confdefs.h
--- a/configure.in
+++ b/configure.in
@@ -1344,16 +1344,17 @@ case "$target" in
 
     ;;
 
 *-darwin*)
     AC_DEFINE(XP_UNIX)
     AC_DEFINE(DARWIN)
     AC_DEFINE(HAVE_BSD_FLOCK)
     AC_DEFINE(HAVE_SOCKLEN_T)
+    AC_DEFINE(HAVE_POINTER_LOCALTIME_R)
     AS='$(CC) -x assembler-with-cpp'
     CFLAGS="$CFLAGS -Wall -fno-common"
     case "${target_cpu}" in
         arm*)
             CPU_ARCH=arm
             ;;
         i*86*|x86_64)
             if test -n "$USE_64"; then
@@ -1784,16 +1785,17 @@ tools are selected during the Xcode/Deve
 *-linux*|*-gnu*|*-k*bsd*-gnu|*-android*|*-linuxandroid*)
     if test -z "$USE_NSPR_THREADS"; then
         USE_PTHREADS=1
         IMPL_STRATEGY=_PTH
     fi
     AC_DEFINE(XP_UNIX)
     AC_DEFINE(_GNU_SOURCE)
     AC_DEFINE(HAVE_FCNTL_FILE_LOCKING)
+    AC_DEFINE(HAVE_POINTER_LOCALTIME_R)
     case "${target}" in
     *-android*|*-linuxandroid*)
         OS_TARGET=Android
         AC_DEFINE(LINUX)
         ;;
     *-linux*)
         AC_DEFINE(LINUX)
         ;;
--- a/pr/src/misc/prtime.c
+++ b/pr/src/misc/prtime.c
@@ -490,16 +490,30 @@ PR_NormalizeTime(PRExplodedTime *time, P
 
 #define MT_safe_localtime(timer, result) \
         (localtime_r(timer, result) == -1 ? NULL: result)
 
 #elif defined(HAVE_POINTER_LOCALTIME_R)
 
 #define MT_safe_localtime localtime_r
 
+#elif defined(_MSC_VER)
+
+/* Visual C++ has had localtime_s() since Visual C++ 2005. */
+
+static struct tm *MT_safe_localtime(const time_t *clock, struct tm *result)
+{
+    errno_t err = localtime_s(result, clock);
+    if (err != 0) {
+        errno = err;
+        return NULL;
+    }
+    return result;
+}
+
 #else
 
 #define HAVE_LOCALTIME_MONITOR 1  /* We use 'monitor' to serialize our calls
                                    * to localtime(). */
 static PRLock *monitor = NULL;
 
 static struct tm *MT_safe_localtime(const time_t *clock, struct tm *result)
 {