Update copyright year to 2014 by running admin/update-copyright.
[emacs.git] / m4 / time_r.m4
blob7e15600f7b60f76850bfe0d057d1e5c26d1d18ff
1 dnl Reentrant time functions: localtime_r, gmtime_r.
3 dnl Copyright (C) 2003, 2006-2014 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 dnl Written by Paul Eggert.
10 AC_DEFUN([gl_TIME_R],
12   dnl Persuade glibc and Solaris <time.h> to declare localtime_r.
13   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15   AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
16   AC_REQUIRE([AC_C_RESTRICT])
18   dnl Some systems don't declare localtime_r() and gmtime_r() if _REENTRANT is
19   dnl not defined.
20   AC_CHECK_DECLS([localtime_r], [], [], [[#include <time.h>]])
21   if test $ac_cv_have_decl_localtime_r = no; then
22     HAVE_DECL_LOCALTIME_R=0
23   fi
25   AC_CHECK_FUNCS_ONCE([localtime_r])
26   if test $ac_cv_func_localtime_r = yes; then
27     HAVE_LOCALTIME_R=1
28     AC_CACHE_CHECK([whether localtime_r is compatible with its POSIX signature],
29       [gl_cv_time_r_posix],
30       [AC_COMPILE_IFELSE(
31          [AC_LANG_PROGRAM(
32             [[#include <time.h>]],
33             [[/* We don't need to append 'restrict's to the argument types,
34                  even though the POSIX signature has the 'restrict's,
35                  since C99 says they can't affect type compatibility.  */
36               struct tm * (*ptr) (time_t const *, struct tm *) = localtime_r;
37               if (ptr) return 0;
38               /* Check the return type is a pointer.
39                  On HP-UX 10 it is 'int'.  */
40               *localtime_r (0, 0);]])
41          ],
42          [gl_cv_time_r_posix=yes],
43          [gl_cv_time_r_posix=no])
44       ])
45     if test $gl_cv_time_r_posix = yes; then
46       REPLACE_LOCALTIME_R=0
47     else
48       REPLACE_LOCALTIME_R=1
49     fi
50   else
51     HAVE_LOCALTIME_R=0
52   fi
55 # Prerequisites of lib/time_r.c.
56 AC_DEFUN([gl_PREREQ_TIME_R], [
57   :