[vlc-commits] compat: fix localtime_r() replacement
Rémi Denis-Courmont
git at videolan.org
Mon Mar 16 18:30:44 CET 2015
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Mar 16 19:20:44 2015 +0200| [d60d5102b861525edf1ba22f9e6c6b3747a4ed3e] | committer: Rémi Denis-Courmont
compat: fix localtime_r() replacement
- Do not clobber thread-specific state on Windows
- Be thread-safe on non-Windows
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d60d5102b861525edf1ba22f9e6c6b3747a4ed3e
---
compat/localtime_r.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/compat/localtime_r.c b/compat/localtime_r.c
index b19f68d..67da422 100644
--- a/compat/localtime_r.c
+++ b/compat/localtime_r.c
@@ -1,7 +1,7 @@
/*****************************************************************************
* localtime_r.c: POSIX localtime_r() replacement
*****************************************************************************
- * Copyright © 1998-2008 VLC authors and VideoLAN
+ * Copyright © 1998-2015 VLC authors and VideoLAN
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
@@ -18,20 +18,26 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
+#if (__STDC_VERSION__ >= 201112L)
+# define __STDC_WANT_LIB_EXT1__ 1
+#endif
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
+#include <errno.h>
#include <time.h>
/* If localtime_r() is not provided, we assume localtime() uses
* thread-specific storage. */
struct tm *localtime_r (const time_t *timep, struct tm *result)
{
- struct tm *s = localtime (timep);
- if (s == NULL)
- return NULL;
-
- *result = *s;
- return result;
+#if (__STDC_VERSION__ >= 201112L)
+ return localtime_s(timep, result);
+#elif defined (_WIN32)
+ return ((errno = localtime_s(result, timep)) == 0) ? result : NULL;
+#else
+# warning localtime_r() not implemented!
+ return gmtime_r(timep, result);
+#endif
}
More information about the vlc-commits
mailing list