summaryrefslogtreecommitdiff
path: root/m4/tzset.m4
blob: ca93899cd51e7030a909895869c3b38025729886 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#serial 1
# See if we have a working tzset function.
# If so, arrange to compile the wrapper function.
# For at least Solaris 2.5.1 and 2.6, this is necessary
# because tzset can clobber the contents of the buffer
# used by localtime.

# Written by Paul Eggert and Jim Meyering.

AC_DEFUN([gl_FUNC_TZSET_CLOBBER],
[
  AC_REQUIRE([AC_HEADER_TIME])
  AC_CACHE_CHECK([whether tzset clobbers localtime buffer],
                 gl_cv_func_tzset_clobber,
  [
  AC_RUN_IFELSE([AC_LANG_SOURCE([[
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
#  include <sys/time.h>
# else
#  include <time.h>
# endif
#endif
#include <stdlib.h>

int
main ()
{
  time_t t1 = 853958121;
  struct tm *p, s;
  putenv ("TZ=GMT0");
  p = localtime (&t1);
  s = *p;
  putenv ("TZ=EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00");
  tzset ();
  exit (p->tm_year != s.tm_year
        || p->tm_mon != s.tm_mon
        || p->tm_mday != s.tm_mday
        || p->tm_hour != s.tm_hour
        || p->tm_min != s.tm_min
        || p->tm_sec != s.tm_sec);
}
  ]])],
       [gl_cv_func_tzset_clobber=no],
       [gl_cv_func_tzset_clobber=yes],
       [gl_cv_func_tzset_clobber=yes])])

  AC_DEFINE(HAVE_RUN_TZSET_TEST, 1,
    [Define to 1 if you have run the test for working tzset.])

  if test $gl_cv_func_tzset_clobber = yes; then
    # Caution: the following few lines should be the same
    # as those in gettimeofday.m4.
    AC_LIBOBJ(gettimeofday)
    AC_DEFINE(gmtime, rpl_gmtime,
      [Define to rpl_gmtime if the replacement function should be used.])
    AC_DEFINE(localtime, rpl_localtime,
      [Define to rpl_localtime if the replacement function should be used.])

    AC_DEFINE(tzset, rpl_tzset,
      [Define to rpl_tzset if the wrapper function should be used.])
    AC_DEFINE(TZSET_CLOBBERS_LOCALTIME_BUFFER, 1,
      [Define if tzset clobbers localtime's static buffer.])
  fi
])