sys_socket: Add support for OpenVMS.
[gnulib.git] / m4 / year2038.m4
blob6e21f631dd90078e60c149eb1dbe15ac921e7483
1 # year2038.m4 serial 1
2 dnl Copyright (C) 2017 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 dnl Attempt to ensure that 'time_t' is a 64-bit type
8 dnl and that the functions time(), stat(), etc. return 64-bit times.
10 AC_DEFUN([gl_YEAR2038_EARLY],
12   AC_REQUIRE([AC_CANONICAL_HOST])
13   case "$host_os" in
14     mingw*)
15       AC_DEFINE([__MINGW_USE_VC2005_COMPAT], [1],
16         [For 64-bit time_t on 32-bit mingw.])
17       ;;
18   esac
21 AC_DEFUN([gl_YEAR2038],
23   AC_REQUIRE([AC_CANONICAL_HOST])
24   case "$host_os" in
25     mingw*)
26       dnl On native Windows, the system include files define types __time32_t
27       dnl and __time64_t. By default, time_t is an alias of
28       dnl   - __time32_t on 32-bit mingw,
29       dnl   - __time64_t on 64-bit mingw and on MSVC (since MSVC 8).
30       dnl But when compiling with -D__MINGW_USE_VC2005_COMPAT, time_t is an
31       dnl alias of __time64_t.
32       dnl And when compiling with -D_USE_32BIT_TIME_T, time_t is an alias of
33       dnl __time32_t.
34       AC_CACHE_CHECK([for 64-bit time_t], [gl_cv_type_time_t_64],
35         [AC_COMPILE_IFELSE(
36            [AC_LANG_PROGRAM(
37               [[#include <time.h>
38                 int verify_time_t_size[sizeof (time_t) >= 8 ? 1 : -1];
39               ]],
40               [[]])],
41            [gl_cv_type_time_t_64=yes], [gl_cv_type_time_t_64=no])
42         ])
43       if test $gl_cv_type_time_t_64 = no; then
44         dnl Just bail out if 'time_t' is not 64-bit, and let the user fix the
45         dnl problem.
46         AC_EGREP_CPP([booboo], [
47           #ifdef _USE_32BIT_TIME_T
48           booboo
49           #endif
50           ],
51           [AC_MSG_FAILURE([This package requires a 64-bit 'time_t' type. Remove _USE_32BIT_TIME_T from the compiler flags.])],
52           [AC_MSG_FAILURE([This package requires a 64-bit 'time_t' type. Your system include files surely provide a way to make 'time_t' an alias of '__time64_t'.])])
53       fi
54       ;;
55     *)
56       dnl On many systems, time_t is already a 64-bit type.
57       dnl On those systems where time_t is still 32-bit, it requires kernel
58       dnl and libc support to make it 64-bit. For glibc on Linux/x86, this
59       dnl is work in progress; see
60       dnl <https://sourceware.org/glibc/wiki/Y2038ProofnessDesign>.
61       ;;
62   esac