summaryrefslogtreecommitdiffstats
path: root/gl/m4
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@aei.ca>2009-03-20 02:48:40 -0400
committerThomas Guyot-Sionnest <dermoth@aei.ca>2009-03-20 02:57:11 -0400
commit3fa3707b5752adfe348e101a194635cc11ace2af (patch)
treeb8a8d4e0c1db4a056ea64224ba7d06dcf630a48b /gl/m4
parentd36c97612990ac81d2dc0452b980e8708477df76 (diff)
downloadmonitoring-plugins-3fa3707b5752adfe348e101a194635cc11ace2af.tar.gz
Add the timegm Gnulib module
Diffstat (limited to 'gl/m4')
-rw-r--r--gl/m4/gnulib-cache.m43
-rw-r--r--gl/m4/gnulib-comp.m412
-rw-r--r--gl/m4/mktime.m4224
-rw-r--r--gl/m4/time_h.m474
-rw-r--r--gl/m4/time_r.m443
-rw-r--r--gl/m4/timegm.m440
6 files changed, 395 insertions, 1 deletions
diff --git a/gl/m4/gnulib-cache.m4 b/gl/m4/gnulib-cache.m4
index eb471340..385f5432 100644
--- a/gl/m4/gnulib-cache.m4
+++ b/gl/m4/gnulib-cache.m4
@@ -15,7 +15,7 @@
15 15
16 16
17# Specification in the form of a command-line invocation: 17# Specification in the form of a command-line invocation:
18# gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-libtool --macro-prefix=gl base64 dirname floorf fsusage getaddrinfo gethostname getloadavg getopt gettext mountlist regex vasprintf vsnprintf 18# gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --no-libtool --macro-prefix=gl base64 dirname floorf fsusage getaddrinfo gethostname getloadavg getopt gettext mountlist regex timegm vasprintf vsnprintf
19 19
20# Specification in the form of a few gnulib-tool.m4 macro invocations: 20# Specification in the form of a few gnulib-tool.m4 macro invocations:
21gl_LOCAL_DIR([]) 21gl_LOCAL_DIR([])
@@ -31,6 +31,7 @@ gl_MODULES([
31 gettext 31 gettext
32 mountlist 32 mountlist
33 regex 33 regex
34 timegm
34 vasprintf 35 vasprintf
35 vsnprintf 36 vsnprintf
36]) 37])
diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4
index 99fa45dc..c6171dea 100644
--- a/gl/m4/gnulib-comp.m4
+++ b/gl/m4/gnulib-comp.m4
@@ -94,6 +94,7 @@ AC_DEFUN([gl_INIT],
94 gl_WCHAR_MODULE_INDICATOR([mbrtowc]) 94 gl_WCHAR_MODULE_INDICATOR([mbrtowc])
95 gl_FUNC_MBSINIT 95 gl_FUNC_MBSINIT
96 gl_WCHAR_MODULE_INDICATOR([mbsinit]) 96 gl_WCHAR_MODULE_INDICATOR([mbsinit])
97 gl_FUNC_MKTIME
97 gl_MOUNTLIST 98 gl_MOUNTLIST
98 gl_MULTIARCH 99 gl_MULTIARCH
99 gl_HEADER_NETDB 100 gl_HEADER_NETDB
@@ -125,6 +126,9 @@ AC_DEFUN([gl_INIT],
125 gl_HEADER_SYS_SOCKET 126 gl_HEADER_SYS_SOCKET
126 gl_MODULE_INDICATOR([sys_socket]) 127 gl_MODULE_INDICATOR([sys_socket])
127 AC_PROG_MKDIR_P 128 AC_PROG_MKDIR_P
129 gl_HEADER_TIME_H
130 gl_TIME_R
131 gl_FUNC_TIMEGM
128 gl_UNISTD_H 132 gl_UNISTD_H
129 gl_UNISTD_SAFER 133 gl_UNISTD_SAFER
130 gl_FUNC_VASNPRINTF 134 gl_FUNC_VASNPRINTF
@@ -332,6 +336,7 @@ AC_DEFUN([gl_FILE_LIST], [
332 lib/math.in.h 336 lib/math.in.h
333 lib/mbrtowc.c 337 lib/mbrtowc.c
334 lib/mbsinit.c 338 lib/mbsinit.c
339 lib/mktime.c
335 lib/mountlist.c 340 lib/mountlist.c
336 lib/mountlist.h 341 lib/mountlist.h
337 lib/netdb.in.h 342 lib/netdb.in.h
@@ -369,6 +374,9 @@ AC_DEFUN([gl_FILE_LIST], [
369 lib/strndup.c 374 lib/strndup.c
370 lib/strnlen.c 375 lib/strnlen.c
371 lib/sys_socket.in.h 376 lib/sys_socket.in.h
377 lib/time.in.h
378 lib/time_r.c
379 lib/timegm.c
372 lib/unistd--.h 380 lib/unistd--.h
373 lib/unistd-safer.h 381 lib/unistd-safer.h
374 lib/unistd.in.h 382 lib/unistd.in.h
@@ -444,6 +452,7 @@ AC_DEFUN([gl_FILE_LIST], [
444 m4/mbrtowc.m4 452 m4/mbrtowc.m4
445 m4/mbsinit.m4 453 m4/mbsinit.m4
446 m4/mbstate_t.m4 454 m4/mbstate_t.m4
455 m4/mktime.m4
447 m4/mountlist.m4 456 m4/mountlist.m4
448 m4/multiarch.m4 457 m4/multiarch.m4
449 m4/netdb_h.m4 458 m4/netdb_h.m4
@@ -475,6 +484,9 @@ AC_DEFUN([gl_FILE_LIST], [
475 m4/strnlen.m4 484 m4/strnlen.m4
476 m4/sys_socket_h.m4 485 m4/sys_socket_h.m4
477 m4/threadlib.m4 486 m4/threadlib.m4
487 m4/time_h.m4
488 m4/time_r.m4
489 m4/timegm.m4
478 m4/uintmax_t.m4 490 m4/uintmax_t.m4
479 m4/unistd-safer.m4 491 m4/unistd-safer.m4
480 m4/unistd_h.m4 492 m4/unistd_h.m4
diff --git a/gl/m4/mktime.m4 b/gl/m4/mktime.m4
new file mode 100644
index 00000000..223b9f1f
--- /dev/null
+++ b/gl/m4/mktime.m4
@@ -0,0 +1,224 @@
1# serial 14
2dnl Copyright (C) 2002-2003, 2005-2007, 2009 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7dnl From Jim Meyering.
8
9# Redefine AC_FUNC_MKTIME, to fix a bug in Autoconf 2.61a and earlier.
10# This redefinition can be removed once a new version of Autoconf is assumed.
11# The redefinition is taken from
12# <http://cvs.sv.gnu.org/viewcvs/*checkout*/autoconf/autoconf/lib/autoconf/functions.m4?rev=1.119>.
13# AC_FUNC_MKTIME
14# --------------
15AC_DEFUN([AC_FUNC_MKTIME],
16[AC_CHECK_HEADERS_ONCE([unistd.h])
17AC_CHECK_FUNCS_ONCE([alarm])
18AC_CACHE_CHECK([for working mktime], [ac_cv_func_working_mktime],
19[AC_RUN_IFELSE([AC_LANG_SOURCE(
20[[/* Test program from Paul Eggert and Tony Leneis. */
21#include <limits.h>
22#include <stdlib.h>
23#include <time.h>
24
25#ifdef HAVE_UNISTD_H
26# include <unistd.h>
27#endif
28
29#ifndef HAVE_ALARM
30# define alarm(X) /* empty */
31#endif
32
33/* Work around redefinition to rpl_putenv by other config tests. */
34#undef putenv
35
36static time_t time_t_max;
37static time_t time_t_min;
38
39/* Values we'll use to set the TZ environment variable. */
40static char *tz_strings[] = {
41 (char *) 0, "TZ=GMT0", "TZ=JST-9",
42 "TZ=EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00"
43};
44#define N_STRINGS (sizeof (tz_strings) / sizeof (tz_strings[0]))
45
46/* Return 0 if mktime fails to convert a date in the spring-forward gap.
47 Based on a problem report from Andreas Jaeger. */
48static int
49spring_forward_gap ()
50{
51 /* glibc (up to about 1998-10-07) failed this test. */
52 struct tm tm;
53
54 /* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0"
55 instead of "TZ=America/Vancouver" in order to detect the bug even
56 on systems that don't support the Olson extension, or don't have the
57 full zoneinfo tables installed. */
58 putenv ("TZ=PST8PDT,M4.1.0,M10.5.0");
59
60 tm.tm_year = 98;
61 tm.tm_mon = 3;
62 tm.tm_mday = 5;
63 tm.tm_hour = 2;
64 tm.tm_min = 0;
65 tm.tm_sec = 0;
66 tm.tm_isdst = -1;
67 return mktime (&tm) != (time_t) -1;
68}
69
70static int
71mktime_test1 (time_t now)
72{
73 struct tm *lt;
74 return ! (lt = localtime (&now)) || mktime (lt) == now;
75}
76
77static int
78mktime_test (time_t now)
79{
80 return (mktime_test1 (now)
81 && mktime_test1 ((time_t) (time_t_max - now))
82 && mktime_test1 ((time_t) (time_t_min + now)));
83}
84
85static int
86irix_6_4_bug ()
87{
88 /* Based on code from Ariel Faigon. */
89 struct tm tm;
90 tm.tm_year = 96;
91 tm.tm_mon = 3;
92 tm.tm_mday = 0;
93 tm.tm_hour = 0;
94 tm.tm_min = 0;
95 tm.tm_sec = 0;
96 tm.tm_isdst = -1;
97 mktime (&tm);
98 return tm.tm_mon == 2 && tm.tm_mday == 31;
99}
100
101static int
102bigtime_test (int j)
103{
104 struct tm tm;
105 time_t now;
106 tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = j;
107 now = mktime (&tm);
108 if (now != (time_t) -1)
109 {
110 struct tm *lt = localtime (&now);
111 if (! (lt
112 && lt->tm_year == tm.tm_year
113 && lt->tm_mon == tm.tm_mon
114 && lt->tm_mday == tm.tm_mday
115 && lt->tm_hour == tm.tm_hour
116 && lt->tm_min == tm.tm_min
117 && lt->tm_sec == tm.tm_sec
118 && lt->tm_yday == tm.tm_yday
119 && lt->tm_wday == tm.tm_wday
120 && ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst)
121 == (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst))))
122 return 0;
123 }
124 return 1;
125}
126
127static int
128year_2050_test ()
129{
130 /* The correct answer for 2050-02-01 00:00:00 in Pacific time,
131 ignoring leap seconds. */
132 unsigned long int answer = 2527315200UL;
133
134 struct tm tm;
135 time_t t;
136 tm.tm_year = 2050 - 1900;
137 tm.tm_mon = 2 - 1;
138 tm.tm_mday = 1;
139 tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
140 tm.tm_isdst = -1;
141
142 /* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0"
143 instead of "TZ=America/Vancouver" in order to detect the bug even
144 on systems that don't support the Olson extension, or don't have the
145 full zoneinfo tables installed. */
146 putenv ("TZ=PST8PDT,M4.1.0,M10.5.0");
147
148 t = mktime (&tm);
149
150 /* Check that the result is either a failure, or close enough
151 to the correct answer that we can assume the discrepancy is
152 due to leap seconds. */
153 return (t == (time_t) -1
154 || (0 < t && answer - 120 <= t && t <= answer + 120));
155}
156
157int
158main ()
159{
160 time_t t, delta;
161 int i, j;
162
163 /* This test makes some buggy mktime implementations loop.
164 Give up after 60 seconds; a mktime slower than that
165 isn't worth using anyway. */
166 alarm (60);
167
168 for (;;)
169 {
170 t = (time_t_max << 1) + 1;
171 if (t <= time_t_max)
172 break;
173 time_t_max = t;
174 }
175 time_t_min = - ((time_t) ~ (time_t) 0 == (time_t) -1) - time_t_max;
176
177 delta = time_t_max / 997; /* a suitable prime number */
178 for (i = 0; i < N_STRINGS; i++)
179 {
180 if (tz_strings[i])
181 putenv (tz_strings[i]);
182
183 for (t = 0; t <= time_t_max - delta; t += delta)
184 if (! mktime_test (t))
185 return 1;
186 if (! (mktime_test ((time_t) 1)
187 && mktime_test ((time_t) (60 * 60))
188 && mktime_test ((time_t) (60 * 60 * 24))))
189 return 1;
190
191 for (j = 1; ; j <<= 1)
192 if (! bigtime_test (j))
193 return 1;
194 else if (INT_MAX / 2 < j)
195 break;
196 if (! bigtime_test (INT_MAX))
197 return 1;
198 }
199 return ! (irix_6_4_bug () && spring_forward_gap () && year_2050_test ());
200}]])],
201 [ac_cv_func_working_mktime=yes],
202 [ac_cv_func_working_mktime=no],
203 [ac_cv_func_working_mktime=no])])
204if test $ac_cv_func_working_mktime = no; then
205 AC_LIBOBJ([mktime])
206fi
207])# AC_FUNC_MKTIME
208
209AC_DEFUN([gl_FUNC_MKTIME],
210[
211 AC_FUNC_MKTIME
212 dnl Note: AC_FUNC_MKTIME does AC_LIBOBJ([mktime]).
213 if test $ac_cv_func_working_mktime = no; then
214 AC_DEFINE([mktime], [rpl_mktime],
215 [Define to rpl_mktime if the replacement function should be used.])
216 gl_PREREQ_MKTIME
217 fi
218])
219
220# Prerequisites of lib/mktime.c.
221AC_DEFUN([gl_PREREQ_MKTIME],
222[
223 AC_REQUIRE([AC_C_INLINE])
224])
diff --git a/gl/m4/time_h.m4 b/gl/m4/time_h.m4
new file mode 100644
index 00000000..d42a635e
--- /dev/null
+++ b/gl/m4/time_h.m4
@@ -0,0 +1,74 @@
1# Configure a more-standard replacement for <time.h>.
2
3# Copyright (C) 2000, 2001, 2003, 2004, 2005, 2006, 2007 Free Software
4# Foundation, Inc.
5
6# This file is free software; the Free Software Foundation
7# gives unlimited permission to copy and/or distribute it,
8# with or without modifications, as long as this notice is preserved.
9
10# Written by Paul Eggert and Jim Meyering.
11
12AC_DEFUN([gl_HEADER_TIME_H],
13[
14 dnl Use AC_REQUIRE here, so that the default behavior below is expanded
15 dnl once only, before all statements that occur in other macros.
16 AC_REQUIRE([gl_HEADER_TIME_H_BODY])
17])
18
19AC_DEFUN([gl_HEADER_TIME_H_BODY],
20[
21 AC_REQUIRE([AC_C_RESTRICT])
22 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
23 gl_CHECK_NEXT_HEADERS([time.h])
24 AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
25])
26
27AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
28[
29 dnl If another module says to replace or to not replace, do that.
30 dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK;
31 dnl this lets maintainers check for portability.
32 REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R])
33 REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP])
34 REPLACE_STRPTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_STRPTIME])
35 REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM])
36])
37
38dnl Define HAVE_STRUCT_TIMESPEC if `struct timespec' is declared
39dnl in time.h or sys/time.h.
40
41AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
42[
43 AC_CHECK_HEADERS_ONCE([sys/time.h])
44 AC_CACHE_CHECK([for struct timespec in <time.h>],
45 [gl_cv_sys_struct_timespec_in_time_h],
46 [AC_COMPILE_IFELSE(
47 [AC_LANG_PROGRAM(
48 [[#include <time.h>
49 ]],
50 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
51 [gl_cv_sys_struct_timespec_in_time_h=yes],
52 [gl_cv_sys_struct_timespec_in_time_h=no])])
53
54 TIME_H_DEFINES_STRUCT_TIMESPEC=0
55 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0
56 if test $gl_cv_sys_struct_timespec_in_time_h = yes; then
57 TIME_H_DEFINES_STRUCT_TIMESPEC=1
58 else
59 AC_CACHE_CHECK([for struct timespec in <sys/time.h>],
60 [gl_cv_sys_struct_timespec_in_sys_time_h],
61 [AC_COMPILE_IFELSE(
62 [AC_LANG_PROGRAM(
63 [[#include <sys/time.h>
64 ]],
65 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
66 [gl_cv_sys_struct_timespec_in_sys_time_h=yes],
67 [gl_cv_sys_struct_timespec_in_sys_time_h=no])])
68 if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then
69 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1
70 fi
71 fi
72 AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC])
73 AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC])
74])
diff --git a/gl/m4/time_r.m4 b/gl/m4/time_r.m4
new file mode 100644
index 00000000..c871b56d
--- /dev/null
+++ b/gl/m4/time_r.m4
@@ -0,0 +1,43 @@
1dnl Reentrant time functions like localtime_r.
2
3dnl Copyright (C) 2003, 2006, 2007, 2008 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7
8dnl Written by Paul Eggert.
9
10AC_DEFUN([gl_TIME_R],
11[
12 dnl Persuade glibc and Solaris <time.h> to declare localtime_r.
13 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
14
15 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
16 AC_REQUIRE([AC_C_RESTRICT])
17
18 AC_CACHE_CHECK([whether localtime_r is compatible with its POSIX signature],
19 [gl_cv_time_r_posix],
20 [AC_TRY_COMPILE(
21 [#include <time.h>],
22 [/* We don't need to append 'restrict's to the argument types,
23 even though the POSIX signature has the 'restrict's,
24 since C99 says they can't affect type compatibility. */
25 struct tm * (*ptr) (time_t const *, struct tm *) = localtime_r;
26 if (ptr) return 0;
27 /* Check the return type is a pointer. On HP-UX 10 it is 'int'. */
28 *localtime_r (0, 0);],
29 [gl_cv_time_r_posix=yes],
30 [gl_cv_time_r_posix=no])])
31 if test $gl_cv_time_r_posix = yes; then
32 REPLACE_LOCALTIME_R=0
33 else
34 REPLACE_LOCALTIME_R=1
35 AC_LIBOBJ([time_r])
36 gl_PREREQ_TIME_R
37 fi
38])
39
40# Prerequisites of lib/time_r.c.
41AC_DEFUN([gl_PREREQ_TIME_R], [
42 :
43])
diff --git a/gl/m4/timegm.m4 b/gl/m4/timegm.m4
new file mode 100644
index 00000000..be323c9b
--- /dev/null
+++ b/gl/m4/timegm.m4
@@ -0,0 +1,40 @@
1# timegm.m4 serial 6
2dnl Copyright (C) 2003, 2007, 2009 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN([gl_FUNC_TIMEGM],
8[
9 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
10 AC_REQUIRE([gl_FUNC_MKTIME])
11 if test $ac_cv_func_working_mktime = no; then
12 # Assume that timegm is buggy if mktime is.
13 AC_LIBOBJ([timegm])
14 ac_cv_func_timegm=no
15 else
16 AC_REPLACE_FUNCS([timegm])
17 fi
18 REPLACE_TIMEGM=1
19 if test $ac_cv_func_timegm = yes; then
20 AC_CHECK_DECLS([timegm], [REPLACE_TIMEGM=0], [], [#include <time.h>])
21 fi
22 if test $REPLACE_TIMEGM = 1; then
23 gl_PREREQ_TIMEGM
24 fi
25])
26
27# Prerequisites of lib/timegm.c.
28AC_DEFUN([gl_PREREQ_TIMEGM], [
29 AC_REQUIRE([gl_TIME_R])
30 AC_REQUIRE([gl_FUNC_MKTIME])
31 if test $ac_cv_func_working_mktime = yes; then
32 AC_CHECK_FUNC([__mktime_internal], ,
33 [# mktime works but it doesn't export __mktime_internal,
34 # so we need to substitute our own mktime implementation.
35 AC_LIBOBJ([mktime])
36 AC_DEFINE([mktime], [rpl_mktime],
37 [Define to rpl_mktime if the replacement function should be used.])
38 gl_PREREQ_MKTIME])
39 fi
40])