sys_socket: Add support for OpenVMS.
[gnulib.git] / m4 / tzset.m4
blob11ceeabed6253ffb7eebf75cf470e3dc4346f40a
1 # serial 10
3 # Copyright (C) 2003, 2007, 2009-2017 Free Software Foundation, Inc.
4 # This file is free software; the Free Software Foundation
5 # gives unlimited permission to copy and/or distribute it,
6 # with or without modifications, as long as this notice is preserved.
8 # See if we have a working tzset function.
9 # If so, arrange to compile the wrapper function.
10 # For at least Solaris 2.5.1 and 2.6, this is necessary
11 # because tzset can clobber the contents of the buffer
12 # used by localtime.
14 # Written by Paul Eggert and Jim Meyering.
16 AC_DEFUN([gl_FUNC_TZSET],
18   AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
19   AC_REQUIRE([gl_LOCALTIME_BUFFER_DEFAULTS])
20   AC_REQUIRE([AC_CANONICAL_HOST])
21   AC_CHECK_FUNCS_ONCE([tzset])
22   if test $ac_cv_func_tzset = no; then
23     HAVE_TZSET=0
24   fi
25   gl_FUNC_TZSET_CLOBBER
26   REPLACE_TZSET=0
27   case "$gl_cv_func_tzset_clobber" in
28     *yes)
29       REPLACE_TZSET=1
30       AC_DEFINE([TZSET_CLOBBERS_LOCALTIME], [1],
31         [Define if tzset clobbers localtime's static buffer.])
32       gl_LOCALTIME_BUFFER_NEEDED
33       ;;
34   esac
35   case "$host_os" in
36     mingw*) REPLACE_TZSET=1 ;;
37   esac
40 # Set gl_cv_func_tzset_clobber.
41 AC_DEFUN([gl_FUNC_TZSET_CLOBBER],
43   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
44   AC_CACHE_CHECK([whether tzset clobbers localtime buffer],
45                  [gl_cv_func_tzset_clobber],
46     [AC_RUN_IFELSE([AC_LANG_SOURCE([[
47 #include <time.h>
48 #include <stdlib.h>
50 int
51 main ()
53   time_t t1 = 853958121;
54   struct tm *p, s;
55   putenv ("TZ=GMT0");
56   p = localtime (&t1);
57   s = *p;
58   putenv ("TZ=EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00");
59   tzset ();
60   return (p->tm_year != s.tm_year
61           || p->tm_mon != s.tm_mon
62           || p->tm_mday != s.tm_mday
63           || p->tm_hour != s.tm_hour
64           || p->tm_min != s.tm_min
65           || p->tm_sec != s.tm_sec);
67   ]])],
68        [gl_cv_func_tzset_clobber=no],
69        [gl_cv_func_tzset_clobber=yes],
70        [case "$host_os" in
71                   # Guess all is fine on glibc systems.
72           *-gnu*) gl_cv_func_tzset_clobber="guessing no" ;;
73                   # Guess no on native Windows.
74           mingw*) gl_cv_func_tzset_clobber="guessing no" ;;
75                   # If we don't know, assume the worst.
76           *)      gl_cv_func_tzset_clobber="guessing yes" ;;
77         esac
78        ])
79     ])
81   AC_DEFINE([HAVE_RUN_TZSET_TEST], [1],
82     [Define to 1 if you have run the test for working tzset.])