1 | #serial 7
|
---|
2 |
|
---|
3 | # Copyright (C) 2001, 2002, 2003, 2005 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.
|
---|
7 |
|
---|
8 | dnl From Jim Meyering.
|
---|
9 | dnl
|
---|
10 | dnl See if gettimeofday clobbers the static buffer that localtime uses
|
---|
11 | dnl for its return value. The gettimeofday function from Mac OS X 10.0.4
|
---|
12 | dnl (i.e., Darwin 1.3.7) has this problem.
|
---|
13 | dnl
|
---|
14 | dnl If it does, then arrange to use gettimeofday and localtime only via
|
---|
15 | dnl the wrapper functions that work around the problem.
|
---|
16 |
|
---|
17 | AC_DEFUN([AC_FUNC_GETTIMEOFDAY_CLOBBER],
|
---|
18 | [
|
---|
19 | AC_REQUIRE([AC_HEADER_TIME])
|
---|
20 | AC_CACHE_CHECK([whether gettimeofday clobbers localtime buffer],
|
---|
21 | jm_cv_func_gettimeofday_clobber,
|
---|
22 | [AC_TRY_RUN([
|
---|
23 | #include <stdio.h>
|
---|
24 | #include <string.h>
|
---|
25 |
|
---|
26 | #if TIME_WITH_SYS_TIME
|
---|
27 | # include <sys/time.h>
|
---|
28 | # include <time.h>
|
---|
29 | #else
|
---|
30 | # if HAVE_SYS_TIME_H
|
---|
31 | # include <sys/time.h>
|
---|
32 | # else
|
---|
33 | # include <time.h>
|
---|
34 | # endif
|
---|
35 | #endif
|
---|
36 |
|
---|
37 | #include <stdlib.h>
|
---|
38 |
|
---|
39 | int
|
---|
40 | main ()
|
---|
41 | {
|
---|
42 | time_t t = 0;
|
---|
43 | struct tm *lt;
|
---|
44 | struct tm saved_lt;
|
---|
45 | struct timeval tv;
|
---|
46 | lt = localtime (&t);
|
---|
47 | saved_lt = *lt;
|
---|
48 | gettimeofday (&tv, NULL);
|
---|
49 | if (memcmp (lt, &saved_lt, sizeof (struct tm)) != 0)
|
---|
50 | exit (1);
|
---|
51 |
|
---|
52 | exit (0);
|
---|
53 | }
|
---|
54 | ],
|
---|
55 | jm_cv_func_gettimeofday_clobber=no,
|
---|
56 | jm_cv_func_gettimeofday_clobber=yes,
|
---|
57 | dnl When crosscompiling, assume it is broken.
|
---|
58 | jm_cv_func_gettimeofday_clobber=yes)
|
---|
59 | ])
|
---|
60 | if test $jm_cv_func_gettimeofday_clobber = yes; then
|
---|
61 | gl_GETTIMEOFDAY_REPLACE_LOCALTIME
|
---|
62 |
|
---|
63 | AC_DEFINE(gettimeofday, rpl_gettimeofday,
|
---|
64 | [Define to rpl_gettimeofday if the replacement function should be used.])
|
---|
65 | gl_PREREQ_GETTIMEOFDAY
|
---|
66 | fi
|
---|
67 | ])
|
---|
68 |
|
---|
69 | AC_DEFUN([gl_GETTIMEOFDAY_REPLACE_LOCALTIME], [
|
---|
70 | AC_LIBOBJ(gettimeofday)
|
---|
71 | AC_DEFINE(gmtime, rpl_gmtime,
|
---|
72 | [Define to rpl_gmtime if the replacement function should be used.])
|
---|
73 | AC_DEFINE(localtime, rpl_localtime,
|
---|
74 | [Define to rpl_localtime if the replacement function should be used.])
|
---|
75 | ])
|
---|
76 |
|
---|
77 | # Prerequisites of lib/gettimeofday.c.
|
---|
78 | AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [
|
---|
79 | AC_REQUIRE([AC_HEADER_TIME])
|
---|
80 | ])
|
---|