Blame m4/time_r.m4

Packit 33f14e
dnl Reentrant time functions: localtime_r, gmtime_r.
Packit 33f14e
Packit 33f14e
dnl Copyright (C) 2003, 2006-2017 Free Software Foundation, Inc.
Packit 33f14e
dnl This file is free software; the Free Software Foundation
Packit 33f14e
dnl gives unlimited permission to copy and/or distribute it,
Packit 33f14e
dnl with or without modifications, as long as this notice is preserved.
Packit 33f14e
Packit 33f14e
dnl Written by Paul Eggert.
Packit 33f14e
Packit 33f14e
AC_DEFUN([gl_TIME_R],
Packit 33f14e
[
Packit 33f14e
  dnl Persuade glibc and Solaris <time.h> to declare localtime_r.
Packit 33f14e
  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
Packit 33f14e
Packit 33f14e
  AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
Packit 33f14e
  AC_REQUIRE([AC_C_RESTRICT])
Packit 33f14e
Packit 33f14e
  dnl Some systems don't declare localtime_r() and gmtime_r() if _REENTRANT is
Packit 33f14e
  dnl not defined.
Packit 33f14e
  AC_CHECK_DECLS([localtime_r], [], [], [[#include <time.h>]])
Packit 33f14e
  if test $ac_cv_have_decl_localtime_r = no; then
Packit 33f14e
    HAVE_DECL_LOCALTIME_R=0
Packit 33f14e
  fi
Packit 33f14e
Packit 33f14e
  AC_CHECK_FUNCS_ONCE([localtime_r])
Packit 33f14e
  if test $ac_cv_func_localtime_r = yes; then
Packit 33f14e
    HAVE_LOCALTIME_R=1
Packit 33f14e
    AC_CACHE_CHECK([whether localtime_r is compatible with its POSIX signature],
Packit 33f14e
      [gl_cv_time_r_posix],
Packit 33f14e
      [AC_COMPILE_IFELSE(
Packit 33f14e
         [AC_LANG_PROGRAM(
Packit 33f14e
            [[#include <time.h>]],
Packit 33f14e
            [[/* We don't need to append 'restrict's to the argument types,
Packit 33f14e
                 even though the POSIX signature has the 'restrict's,
Packit 33f14e
                 since C99 says they can't affect type compatibility.  */
Packit 33f14e
              struct tm * (*ptr) (time_t const *, struct tm *) = localtime_r;
Packit 33f14e
              if (ptr) return 0;
Packit 33f14e
              /* Check the return type is a pointer.
Packit 33f14e
                 On HP-UX 10 it is 'int'.  */
Packit 33f14e
              *localtime_r (0, 0);]])
Packit 33f14e
         ],
Packit 33f14e
         [gl_cv_time_r_posix=yes],
Packit 33f14e
         [gl_cv_time_r_posix=no])
Packit 33f14e
      ])
Packit 33f14e
    if test $gl_cv_time_r_posix = yes; then
Packit 33f14e
      REPLACE_LOCALTIME_R=0
Packit 33f14e
    else
Packit 33f14e
      REPLACE_LOCALTIME_R=1
Packit 33f14e
    fi
Packit 33f14e
  else
Packit 33f14e
    HAVE_LOCALTIME_R=0
Packit 33f14e
  fi
Packit 33f14e
])
Packit 33f14e
Packit 33f14e
# Prerequisites of lib/time_r.c.
Packit 33f14e
AC_DEFUN([gl_PREREQ_TIME_R], [
Packit 33f14e
  :
Packit 33f14e
])