Add wrappers for gmtime and tzset, too.
[gnulib.git] / m4 / tzset.m4
1 #serial 1
2 # See if we have a working tzset function.
3 # If so, arrange to compile the wrapper function.
4 # For at least Solaris 2.5.1 and 2.6, this is necessary
5 # because tzset can clobber the contents of the buffer
6 # used by localtime.
7
8 # Written by Paul Eggert and Jim Meyering.
9
10 AC_DEFUN([gl_FUNC_TZSET_CLOBBER],
11 [
12   AC_REQUIRE([AC_HEADER_TIME])
13   AC_CACHE_CHECK([whether tzset clobbers localtime buffer],
14                  gl_cv_func_tzset_clobber,
15   [
16   AC_RUN_IFELSE([AC_LANG_SOURCE([[
17 #if TIME_WITH_SYS_TIME
18 # include <sys/time.h>
19 # include <time.h>
20 #else
21 # if HAVE_SYS_TIME_H
22 #  include <sys/time.h>
23 # else
24 #  include <time.h>
25 # endif
26 #endif
27 #include <stdlib.h>
28
29 int
30 main ()
31 {
32   time_t t1 = 853958121;
33   struct tm *p, s;
34   putenv ("TZ=GMT0");
35   p = localtime (&t1);
36   s = *p;
37   putenv ("TZ=EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00");
38   tzset ();
39   exit (p->tm_year != s.tm_year
40         || p->tm_mon != s.tm_mon
41         || p->tm_mday != s.tm_mday
42         || p->tm_hour != s.tm_hour
43         || p->tm_min != s.tm_min
44         || p->tm_sec != s.tm_sec);
45 }
46   ]])],
47        [gl_cv_func_tzset_clobber=no],
48        [gl_cv_func_tzset_clobber=yes],
49        [gl_cv_func_tzset_clobber=yes])])
50
51   AC_DEFINE(HAVE_RUN_TZSET_TEST, 1,
52     [Define to 1 if you have run the test for working tzset.])
53
54   if test $gl_cv_func_tzset_clobber = yes; then
55     gl_GETTIMEOFDAY_REPLACE_LOCALTIME
56
57     AC_DEFINE(tzset, rpl_tzset,
58       [Define to rpl_tzset if the wrapper function should be used.])
59     AC_DEFINE(TZSET_CLOBBERS_LOCALTIME_BUFFER, 1,
60       [Define if tzset clobbers localtime's static buffer.])
61   fi
62 ])