Mercurial > hg > octave-lojdl > gnulib-hg
annotate m4/gettimeofday.m4 @ 5611:87c42e194f4a
Use an all-permissive copyright notice, recommended by RMS.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Sun, 23 Jan 2005 08:06:57 +0000 |
parents | f411b1e0c5bd |
children | d094f71e51d4 |
rev | line source |
---|---|
5611
87c42e194f4a
Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4694
diff
changeset
|
1 #serial 6 |
87c42e194f4a
Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4694
diff
changeset
|
2 |
87c42e194f4a
Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4694
diff
changeset
|
3 # Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. |
87c42e194f4a
Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4694
diff
changeset
|
4 # This file is free software; the Free Software Foundation |
87c42e194f4a
Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4694
diff
changeset
|
5 # gives unlimited permission to copy and/or distribute it, |
87c42e194f4a
Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4694
diff
changeset
|
6 # with or without modifications, as long as this notice is preserved. |
3295 | 7 |
8 dnl From Jim Meyering. | |
9 dnl | |
10 dnl See if gettimeofday clobbers the static buffer that localtime uses | |
5611
87c42e194f4a
Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4694
diff
changeset
|
11 dnl for its return value. The gettimeofday function from Mac OS X 10.0.4 |
87c42e194f4a
Use an all-permissive copyright notice, recommended by RMS.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4694
diff
changeset
|
12 dnl (i.e., Darwin 1.3.7) has this problem. |
3295 | 13 dnl |
3856
16a28d7390aa
(AC_FUNC_GETTIMEOFDAY_CLOBBER): Also replace localtime.
Jim Meyering <jim@meyering.net>
parents:
3486
diff
changeset
|
14 dnl If it does, then arrange to use gettimeofday and localtime only via |
16a28d7390aa
(AC_FUNC_GETTIMEOFDAY_CLOBBER): Also replace localtime.
Jim Meyering <jim@meyering.net>
parents:
3486
diff
changeset
|
15 dnl the wrapper functions that work around the problem. |
3295 | 16 |
3332 | 17 AC_DEFUN([AC_FUNC_GETTIMEOFDAY_CLOBBER], |
3295 | 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> | |
4694 | 24 #include <string.h> |
3295 | 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 | |
4694 | 37 #include <stdlib.h> |
3295 | 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 ], | |
3332 | 55 jm_cv_func_gettimeofday_clobber=no, |
3295 | 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 | |
4540
fa39e8b4a0c2
Add wrappers for gmtime and tzset, too.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4108
diff
changeset
|
61 gl_GETTIMEOFDAY_REPLACE_LOCALTIME |
fa39e8b4a0c2
Add wrappers for gmtime and tzset, too.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4108
diff
changeset
|
62 |
3486
c5e203e2e4d4
Use AC_DEFINE rather than AC_DEFINE_UNQUOTED, whenever the right hand side need not be expanded by the shell.
Jim Meyering <jim@meyering.net>
parents:
3333
diff
changeset
|
63 AC_DEFINE(gettimeofday, rpl_gettimeofday, |
3295 | 64 [Define to rpl_gettimeofday if the replacement function should be used.]) |
3332 | 65 AC_DEFINE(GETTIMEOFDAY_CLOBBERS_LOCALTIME_BUFFER, 1, |
66 [Define if gettimeofday clobbers localtime's static buffer.]) | |
4108
c1d472db5c30
An independent .m4 file for each module.
Bruno Haible <bruno@clisp.org>
parents:
3856
diff
changeset
|
67 gl_PREREQ_GETTIMEOFDAY |
3295 | 68 fi |
69 ]) | |
4108
c1d472db5c30
An independent .m4 file for each module.
Bruno Haible <bruno@clisp.org>
parents:
3856
diff
changeset
|
70 |
4540
fa39e8b4a0c2
Add wrappers for gmtime and tzset, too.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4108
diff
changeset
|
71 AC_DEFUN([gl_GETTIMEOFDAY_REPLACE_LOCALTIME], [ |
fa39e8b4a0c2
Add wrappers for gmtime and tzset, too.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4108
diff
changeset
|
72 AC_LIBOBJ(gettimeofday) |
fa39e8b4a0c2
Add wrappers for gmtime and tzset, too.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4108
diff
changeset
|
73 AC_DEFINE(gmtime, rpl_gmtime, |
fa39e8b4a0c2
Add wrappers for gmtime and tzset, too.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4108
diff
changeset
|
74 [Define to rpl_gmtime if the replacement function should be used.]) |
fa39e8b4a0c2
Add wrappers for gmtime and tzset, too.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4108
diff
changeset
|
75 AC_DEFINE(localtime, rpl_localtime, |
fa39e8b4a0c2
Add wrappers for gmtime and tzset, too.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4108
diff
changeset
|
76 [Define to rpl_localtime if the replacement function should be used.]) |
fa39e8b4a0c2
Add wrappers for gmtime and tzset, too.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4108
diff
changeset
|
77 ]) |
fa39e8b4a0c2
Add wrappers for gmtime and tzset, too.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4108
diff
changeset
|
78 |
4108
c1d472db5c30
An independent .m4 file for each module.
Bruno Haible <bruno@clisp.org>
parents:
3856
diff
changeset
|
79 # Prerequisites of lib/gettimeofday.c. |
c1d472db5c30
An independent .m4 file for each module.
Bruno Haible <bruno@clisp.org>
parents:
3856
diff
changeset
|
80 AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [ |
c1d472db5c30
An independent .m4 file for each module.
Bruno Haible <bruno@clisp.org>
parents:
3856
diff
changeset
|
81 AC_REQUIRE([AC_HEADER_TIME]) |
c1d472db5c30
An independent .m4 file for each module.
Bruno Haible <bruno@clisp.org>
parents:
3856
diff
changeset
|
82 ]) |