[vlc-commits] [Git][videolan/vlc][master] 3 commits: compat: implement windows specific gmtime_r

Steve Lhomme (@robUx4) gitlab at videolan.org
Fri Jan 20 07:32:29 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
6f240f6c by Steve Lhomme at 2023-01-20T07:17:07+00:00
compat: implement windows specific gmtime_r

gmtime_s is the counterpart variant. Just like we use localtime_s for
localtime_r.

- - - - -
ea876bf8 by Steve Lhomme at 2023-01-20T07:17:07+00:00
configure: detect gmtime_r/localtime_r the standard way

The mingw-w64 variants doesn't set the errno, so use our compat version.

- - - - -
571cda19 by Steve Lhomme at 2023-01-20T07:17:07+00:00
localtime_r: don't set errno on success

- - - - -


4 changed files:

- compat/gmtime_r.c
- compat/localtime_r.c
- configure.ac
- meson.build


Changes:

=====================================
compat/gmtime_r.c
=====================================
@@ -28,6 +28,13 @@
 
 struct tm *gmtime_r (const time_t *timep, struct tm *tm)
 {
+#if defined (_WIN32)
+    errno_t ret = gmtime_s(tm, timep);
+    if (ret == 0)
+        return tm;
+    errno = ret;
+    return NULL;
+#else // !_WIN32
     static const unsigned short normal[12] =
         { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
     static const unsigned short leap[12] =
@@ -92,4 +99,5 @@ struct tm *gmtime_r (const time_t *timep, struct tm *tm)
 
     tm->tm_isdst = 0; /* UTC time */
     return tm;
+#endif // !_WIN32
 }


=====================================
compat/localtime_r.c
=====================================
@@ -37,7 +37,11 @@ struct tm *localtime_r (const time_t *timep, struct tm *result)
 #if (__STDC_WANT_LIB_EXT1__)
     return localtime_s(timep, result);
 #elif defined (_WIN32)
-    return ((errno = localtime_s(result, timep)) == 0) ? result : NULL;
+    errno_t ret = localtime_s(result, timep);
+    if (ret == 0)
+        return result;
+    errno = ret;
+    return NULL;
 #else
 # warning localtime_r() not implemented!
     return gmtime_r(timep, result);


=====================================
configure.ac
=====================================
@@ -739,7 +739,7 @@ need_libc=false
 
 dnl Check for usual libc functions
 AC_CHECK_FUNCS([accept4 dup3 fcntl flock fstatat fstatvfs fork getmntent_r getenv getpwuid_r isatty memalign mkostemp mmap open_memstream newlocale pipe2 posix_fadvise setlocale stricmp uselocale wordexp])
-AC_REPLACE_FUNCS([aligned_alloc atof atoll dirfd fdopendir flockfile fsync getdelim getpid lfind lldiv memrchr nrand48 poll posix_memalign readv recvmsg rewind sendmsg setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strnstr strsep strtof strtok_r strtoll swab tdestroy tfind timegm timespec_get strverscmp writev])
+AC_REPLACE_FUNCS([aligned_alloc atof atoll dirfd fdopendir flockfile fsync getdelim getpid gmtime_r lfind lldiv localtime_r memrchr nrand48 poll posix_memalign readv recvmsg rewind sendmsg setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strnstr strsep strtof strtok_r strtoll swab tdestroy tfind timegm timespec_get strverscmp writev])
 AC_REPLACE_FUNCS([gettimeofday])
 AC_CHECK_FUNC(fdatasync,,
   [AC_DEFINE(fdatasync, fsync, [Alias fdatasync() to fsync() if missing.])
@@ -750,8 +750,6 @@ VLC_REPLACE_DECL([realpath], [#include <stdlib.h>])
 dnl mingw64 implements those as static inline, not functions with C linkage
 VLC_REPLACE_DECL([asprintf], [#include <stdio.h>])
 VLC_REPLACE_DECL([vasprintf], [#include <stdio.h>])
-VLC_REPLACE_DECL([gmtime_r], [#include <time.h>])
-VLC_REPLACE_DECL([localtime_r], [#include <time.h>])
 
 dnl C11 static_assert()
 AC_MSG_CHECKING([for static_assert in assert.h])


=====================================
meson.build
=====================================
@@ -606,6 +606,8 @@ libcompat_functions = [
     ['tfind',            '#include <search.h>'],
     ['timegm',           '#include <time.h>'],
     ['timespec_get',     '#include <time.h>'],
+    ['gmtime_r',         '#include <time.h>'],
+    ['localtime_r',      '#include <time.h>'],
     ['strverscmp',       '#include <string.h>'],
     ['writev',           '#include <sys/uio.h>'],
 
@@ -644,11 +646,9 @@ endforeach
 # These functions need to be checked with has_header_symbol as
 # MinGW-w64 implements those as static inline, not functions with C linkage
 libcompat_functions = [
-    ['gmtime_r',         'time.h'],
     ['realpath',         'stdlib.h'],
     ['asprintf',         'stdio.h'],
     ['vasprintf',        'stdio.h'],
-    ['localtime_r',      'time.h'],
 ]
 
 foreach f : libcompat_functions



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/142317c38d453a19917bef95754861931d7ba2cd...571cda19582aba02c851bcb9cf4e1fb3bce30bbe

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/142317c38d453a19917bef95754861931d7ba2cd...571cda19582aba02c851bcb9cf4e1fb3bce30bbe
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list