Blame m4/time_r.m4

Packit aea12f
dnl Reentrant time functions: localtime_r, gmtime_r.
Packit aea12f
Packit Service 991b93
dnl Copyright (C) 2003, 2006-2020 Free Software Foundation, Inc.
Packit aea12f
dnl This file is free software; the Free Software Foundation
Packit aea12f
dnl gives unlimited permission to copy and/or distribute it,
Packit aea12f
dnl with or without modifications, as long as this notice is preserved.
Packit aea12f
Packit aea12f
dnl Written by Paul Eggert.
Packit aea12f
Packit aea12f
AC_DEFUN([gl_TIME_R],
Packit aea12f
[
Packit aea12f
  dnl Persuade glibc and Solaris <time.h> to declare localtime_r.
Packit aea12f
  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
Packit aea12f
Packit aea12f
  AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
Packit aea12f
  AC_REQUIRE([AC_C_RESTRICT])
Packit aea12f
Packit aea12f
  dnl Some systems don't declare localtime_r() and gmtime_r() if _REENTRANT is
Packit aea12f
  dnl not defined.
Packit Service 991b93
  AC_CHECK_DECLS([localtime_r], [], [],
Packit Service 991b93
    [[/* mingw's <time.h> provides the functions asctime_r, ctime_r,
Packit Service 991b93
         gmtime_r, localtime_r only if <unistd.h> or <pthread.h> has
Packit Service 991b93
         been included before.  */
Packit Service 991b93
      #if defined __MINGW32__
Packit Service 991b93
      # include <unistd.h>
Packit Service 991b93
      #endif
Packit Service 991b93
      #include <time.h>
Packit Service 991b93
    ]])
Packit aea12f
  if test $ac_cv_have_decl_localtime_r = no; then
Packit aea12f
    HAVE_DECL_LOCALTIME_R=0
Packit aea12f
  fi
Packit aea12f
Packit aea12f
  AC_CHECK_FUNCS_ONCE([localtime_r])
Packit aea12f
  if test $ac_cv_func_localtime_r = yes; then
Packit aea12f
    HAVE_LOCALTIME_R=1
Packit aea12f
    AC_CACHE_CHECK([whether localtime_r is compatible with its POSIX signature],
Packit aea12f
      [gl_cv_time_r_posix],
Packit aea12f
      [AC_COMPILE_IFELSE(
Packit aea12f
         [AC_LANG_PROGRAM(
Packit Service 991b93
            [[/* mingw's <time.h> provides the functions asctime_r, ctime_r,
Packit Service 991b93
                 gmtime_r, localtime_r only if <unistd.h> or <pthread.h> has
Packit Service 991b93
                 been included before.  */
Packit Service 991b93
              #if defined __MINGW32__
Packit Service 991b93
              # include <unistd.h>
Packit Service 991b93
              #endif
Packit Service 991b93
              #include <time.h>
Packit Service 991b93
            ]],
Packit aea12f
            [[/* We don't need to append 'restrict's to the argument types,
Packit aea12f
                 even though the POSIX signature has the 'restrict's,
Packit aea12f
                 since C99 says they can't affect type compatibility.  */
Packit aea12f
              struct tm * (*ptr) (time_t const *, struct tm *) = localtime_r;
Packit aea12f
              if (ptr) return 0;
Packit aea12f
              /* Check the return type is a pointer.
Packit aea12f
                 On HP-UX 10 it is 'int'.  */
Packit aea12f
              *localtime_r (0, 0);]])
Packit aea12f
         ],
Packit aea12f
         [gl_cv_time_r_posix=yes],
Packit aea12f
         [gl_cv_time_r_posix=no])
Packit aea12f
      ])
Packit aea12f
    if test $gl_cv_time_r_posix = yes; then
Packit aea12f
      REPLACE_LOCALTIME_R=0
Packit aea12f
    else
Packit aea12f
      REPLACE_LOCALTIME_R=1
Packit aea12f
    fi
Packit aea12f
  else
Packit aea12f
    HAVE_LOCALTIME_R=0
Packit Service 991b93
    dnl On mingw, localtime_r() is defined as an inline function; use through a
Packit Service 991b93
    dnl direct function call works but the use as a function pointer leads to a
Packit Service 991b93
    dnl link error.
Packit Service 991b93
    AC_CACHE_CHECK([whether localtime_r exists as an inline function],
Packit Service 991b93
      [gl_cv_func_localtime_r_inline],
Packit Service 991b93
      [AC_LINK_IFELSE(
Packit Service 991b93
         [AC_LANG_PROGRAM(
Packit Service 991b93
            [[/* mingw's <time.h> provides the functions asctime_r, ctime_r,
Packit Service 991b93
                 gmtime_r, localtime_r only if <unistd.h> or <pthread.h> has
Packit Service 991b93
                 been included before.  */
Packit Service 991b93
              #if defined __MINGW32__
Packit Service 991b93
              # include <unistd.h>
Packit Service 991b93
              #endif
Packit Service 991b93
              #include <time.h>
Packit Service 991b93
            ]],
Packit Service 991b93
            [[time_t a;
Packit Service 991b93
              struct tm r;
Packit Service 991b93
              localtime_r (&a, &r);
Packit Service 991b93
            ]])
Packit Service 991b93
         ],
Packit Service 991b93
         [gl_cv_func_localtime_r_inline=yes],
Packit Service 991b93
         [gl_cv_func_localtime_r_inline=no])
Packit Service 991b93
      ])
Packit Service 991b93
    if test $gl_cv_func_localtime_r_inline = yes; then
Packit Service 991b93
      REPLACE_LOCALTIME_R=1
Packit Service 991b93
    fi
Packit aea12f
  fi
Packit aea12f
])
Packit aea12f
Packit aea12f
# Prerequisites of lib/time_r.c.
Packit aea12f
AC_DEFUN([gl_PREREQ_TIME_R], [
Packit aea12f
  :
Packit aea12f
])