summaryrefslogtreecommitdiffstats
path: root/gl/m4/time_r.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gl/m4/time_r.m4')
-rw-r--r--gl/m4/time_r.m449
1 files changed, 45 insertions, 4 deletions
diff --git a/gl/m4/time_r.m4 b/gl/m4/time_r.m4
index c388a83..adce438 100644
--- a/gl/m4/time_r.m4
+++ b/gl/m4/time_r.m4
@@ -1,6 +1,6 @@
1dnl Reentrant time functions: localtime_r, gmtime_r. 1dnl Reentrant time functions: localtime_r, gmtime_r.
2 2
3dnl Copyright (C) 2003, 2006-2013 Free Software Foundation, Inc. 3dnl Copyright (C) 2003, 2006-2023 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
@@ -12,12 +12,20 @@ AC_DEFUN([gl_TIME_R],
12 dnl Persuade glibc and Solaris <time.h> to declare localtime_r. 12 dnl Persuade glibc and Solaris <time.h> to declare localtime_r.
13 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) 13 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
14 14
15 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS]) 15 AC_REQUIRE([gl_TIME_H_DEFAULTS])
16 AC_REQUIRE([AC_C_RESTRICT]) 16 AC_REQUIRE([AC_C_RESTRICT])
17 17
18 dnl Some systems don't declare localtime_r() and gmtime_r() if _REENTRANT is 18 dnl Some systems don't declare localtime_r() and gmtime_r() if _REENTRANT is
19 dnl not defined. 19 dnl not defined.
20 AC_CHECK_DECLS([localtime_r], [], [], [[#include <time.h>]]) 20 AC_CHECK_DECLS([localtime_r], [], [],
21 [[/* mingw's <time.h> provides the functions asctime_r, ctime_r,
22 gmtime_r, localtime_r only if <unistd.h> or <pthread.h> has
23 been included before. */
24 #if defined __MINGW32__
25 # include <unistd.h>
26 #endif
27 #include <time.h>
28 ]])
21 if test $ac_cv_have_decl_localtime_r = no; then 29 if test $ac_cv_have_decl_localtime_r = no; then
22 HAVE_DECL_LOCALTIME_R=0 30 HAVE_DECL_LOCALTIME_R=0
23 fi 31 fi
@@ -29,7 +37,14 @@ AC_DEFUN([gl_TIME_R],
29 [gl_cv_time_r_posix], 37 [gl_cv_time_r_posix],
30 [AC_COMPILE_IFELSE( 38 [AC_COMPILE_IFELSE(
31 [AC_LANG_PROGRAM( 39 [AC_LANG_PROGRAM(
32 [[#include <time.h>]], 40 [[/* mingw's <time.h> provides the functions asctime_r, ctime_r,
41 gmtime_r, localtime_r only if <unistd.h> or <pthread.h> has
42 been included before. */
43 #if defined __MINGW32__
44 # include <unistd.h>
45 #endif
46 #include <time.h>
47 ]],
33 [[/* We don't need to append 'restrict's to the argument types, 48 [[/* We don't need to append 'restrict's to the argument types,
34 even though the POSIX signature has the 'restrict's, 49 even though the POSIX signature has the 'restrict's,
35 since C99 says they can't affect type compatibility. */ 50 since C99 says they can't affect type compatibility. */
@@ -49,6 +64,32 @@ AC_DEFUN([gl_TIME_R],
49 fi 64 fi
50 else 65 else
51 HAVE_LOCALTIME_R=0 66 HAVE_LOCALTIME_R=0
67 dnl On mingw, localtime_r() is defined as an inline function; use through a
68 dnl direct function call works but the use as a function pointer leads to a
69 dnl link error.
70 AC_CACHE_CHECK([whether localtime_r exists as an inline function],
71 [gl_cv_func_localtime_r_inline],
72 [AC_LINK_IFELSE(
73 [AC_LANG_PROGRAM(
74 [[/* mingw's <time.h> provides the functions asctime_r, ctime_r,
75 gmtime_r, localtime_r only if <unistd.h> or <pthread.h> has
76 been included before. */
77 #if defined __MINGW32__
78 # include <unistd.h>
79 #endif
80 #include <time.h>
81 ]],
82 [[time_t a;
83 struct tm r;
84 localtime_r (&a, &r);
85 ]])
86 ],
87 [gl_cv_func_localtime_r_inline=yes],
88 [gl_cv_func_localtime_r_inline=no])
89 ])
90 if test $gl_cv_func_localtime_r_inline = yes; then
91 REPLACE_LOCALTIME_R=1
92 fi
52 fi 93 fi
53]) 94])
54 95