Debian Codegraph @

m4/time_r.m4

raw
1 # time_r.m4
2 # serial 1
3 dnl Copyright (C) 2003, 2006-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
8
9 dnl Reentrant time functions: localtime_r, gmtime_r.
10
11 dnl Written by Paul Eggert.
12
13 AC_DEFUN([gl_TIME_R],
14 [
15 dnl Persuade glibc and Solaris <time.h> to declare localtime_r.
16 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
17
18 AC_REQUIRE([gl_TIME_H_DEFAULTS])
19 AC_REQUIRE([AC_C_RESTRICT])
20
21 dnl Some systems don't declare localtime_r() and gmtime_r() if _REENTRANT is
22 dnl not defined.
23 AC_CHECK_DECLS([localtime_r], [], [],
24 [[/* mingw's <time.h> provides the functions asctime_r, ctime_r,
25 gmtime_r, localtime_r only if <unistd.h> or <pthread.h> has
26 been included before. */
27 #if defined __MINGW32__
28 # include <unistd.h>
29 #endif
30 #include <time.h>
31 ]])
32 if test $ac_cv_have_decl_localtime_r = no; then
33 HAVE_DECL_LOCALTIME_R=0
34 fi
35
36 AC_CHECK_FUNCS_ONCE([localtime_r])
37 if test $ac_cv_func_localtime_r = yes; then
38 HAVE_LOCALTIME_R=1
39 AC_CACHE_CHECK([whether localtime_r is compatible with its POSIX signature],
40 [gl_cv_time_r_posix],
41 [AC_COMPILE_IFELSE(
42 [AC_LANG_PROGRAM(
43 [[/* mingw's <time.h> provides the functions asctime_r, ctime_r,
44 gmtime_r, localtime_r only if <unistd.h> or <pthread.h> has
45 been included before. */
46 #if defined __MINGW32__
47 # include <unistd.h>
48 #endif
49 #include <time.h>
50 ]],
51 [[/* We don't need to append 'restrict's to the argument types,
52 even though the POSIX signature has the 'restrict's,
53 since C99 says they can't affect type compatibility. */
54 struct tm * (*ptr) (time_t const *, struct tm *) = localtime_r;
55 if (ptr) return 0;
56 /* Check the return type is a pointer.
57 On HP-UX 10 it is 'int'. */
58 *localtime_r (0, 0);]])
59 ],
60 [gl_cv_time_r_posix=yes],
61 [gl_cv_time_r_posix=no])
62 ])
63 if test $gl_cv_time_r_posix != yes; then
64 REPLACE_LOCALTIME_R=1
65 fi
66 else
67 HAVE_LOCALTIME_R=0
68 dnl On mingw, localtime_r() is defined as an inline function; use through a
69 dnl direct function call works but the use as a function pointer leads to a
70 dnl link error.
71 AC_CACHE_CHECK([whether localtime_r exists as an inline function],
72 [gl_cv_func_localtime_r_inline],
73 [AC_LINK_IFELSE(
74 [AC_LANG_PROGRAM(
75 [[/* mingw's <time.h> provides the functions asctime_r, ctime_r,
76 gmtime_r, localtime_r only if <unistd.h> or <pthread.h> has
77 been included before. */
78 #if defined __MINGW32__
79 # include <unistd.h>
80 #endif
81 #include <time.h>
82 ]],
83 [[time_t a;
84 struct tm r;
85 localtime_r (&a, &r);
86 ]])
87 ],
88 [gl_cv_func_localtime_r_inline=yes],
89 [gl_cv_func_localtime_r_inline=no])
90 ])
91 if test $gl_cv_func_localtime_r_inline = yes; then
92 REPLACE_LOCALTIME_R=1
93 fi
94 fi
95 ])
96
97 # Prerequisites of lib/time_r.c.
98 AC_DEFUN([gl_PREREQ_TIME_R], [
99 :
100 ])