summaryrefslogtreecommitdiff
path: root/m4/sys_time_h.m4
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2012-01-28 18:12:10 +0100
committerBruno Haible <bruno@clisp.org>2012-01-28 18:12:10 +0100
commitf8e84098084b3b53bc6943a5542af1f607ffd477 (patch)
tree7d82e52468f5450b34c46d0810a29abfa117ceec /m4/sys_time_h.m4
parentc47bb7060a7947d3c454a54f4b80b3c8283407d0 (diff)
downloadgnulib-f8e84098084b3b53bc6943a5542af1f607ffd477.tar.gz
sys_time: Override 'struct timeval' on some native Windows platforms.
* m4/sys_time_h.m4 (gl_HEADER_SYS_TIME_H_BODY): Test whether tv_sec has the right type. Set REPLACE_STRUCT_TIMEVAL if not. (gl_HEADER_SYS_TIME_H_DEFAULTS): Initialize REPLACE_STRUCT_TIMEVAL. * lib/sys_time.in.h: Include <winsock2.h> also when 'struct timeval' needs to be overridden. (timeval): Override if REPLACE_STRUCT_TIMEVAL is set. * modules/sys_time (Makefile.am): Substitute REPLACE_STRUCT_TIMEVAL. * tests/test-sys_select.c: Check that the tv_sec member has the same size as a 'time_t'. * tests/test-sys_time.c: Likewise. * m4/gettimeofday.m4 (gl_FUNC_GETTIMEOFDAY): If REPLACE_STRUCT_TIMEVAL is set, set also REPLACE_GETTIMEOFDAY. * lib/gettimeofday.c (gettimeofday): If 'struct timeval' is overridden, convert the resulting 'struct timeval' before returning. * lib/select.c: Include <sys/time.h>. (select, timeval): Undefine at the right place. * modules/select (Depends-on): Add sys_time. * doc/posix-headers/sys_time.texi: Mention the problem with tv_sec on some Windows platforms. Reported by Marc-André Lureau <marcandre.lureau@redhat.com>.
Diffstat (limited to 'm4/sys_time_h.m4')
-rw-r--r--m4/sys_time_h.m432
1 files changed, 30 insertions, 2 deletions
diff --git a/m4/sys_time_h.m4 b/m4/sys_time_h.m4
index bed379785e..26eaf8ea7f 100644
--- a/m4/sys_time_h.m4
+++ b/m4/sys_time_h.m4
@@ -1,5 +1,5 @@
# Configure a replacement for <sys/time.h>.
-# serial 7
+# serial 8
# Copyright (C) 2007, 2009-2012 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
@@ -43,9 +43,36 @@ AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY],
]],
[[static struct timeval x; x.tv_sec = x.tv_usec;]])],
[gl_cv_sys_struct_timeval=yes],
- [gl_cv_sys_struct_timeval=no])])
+ [gl_cv_sys_struct_timeval=no])
+ ])
if test $gl_cv_sys_struct_timeval != yes; then
HAVE_STRUCT_TIMEVAL=0
+ else
+ dnl On native Windows with a 64-bit 'time_t', 'struct timeval' is defined
+ dnl (in <sys/time.h> and <winsock2.h> for mingw64, in <winsock2.h> only
+ dnl for MSVC) with a tv_sec field of type 'long' (32-bit!), which is
+ dnl smaller than the 'time_t' type mandated by POSIX.
+ AC_CACHE_CHECK([for correct struct timeval.tv_sec member],
+ [gl_cv_sys_struct_timeval_tv_sec],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#if HAVE_SYS_TIME_H
+ #include <sys/time.h>
+ #endif
+ #include <time.h>
+ #if HAVE_WINSOCK2_H
+ # include <winsock2.h>
+ #endif
+ ]],
+ [[static struct timeval x;
+ typedef int verify_tv_sec_type[sizeof (x.tv_sec) == sizeof (time_t) ? 1 : -1];
+ ]])],
+ [gl_cv_sys_struct_timeval_tv_sec=yes],
+ [gl_cv_sys_struct_timeval_tv_sec=no])
+ ])
+ if test $gl_cv_sys_struct_timeval_tv_sec != yes; then
+ REPLACE_STRUCT_TIMEVAL=1
+ fi
fi
dnl Check for declarations of anything we want to poison if the
@@ -75,4 +102,5 @@ AC_DEFUN([gl_HEADER_SYS_TIME_H_DEFAULTS],
HAVE_STRUCT_TIMEVAL=1; AC_SUBST([HAVE_STRUCT_TIMEVAL])
HAVE_SYS_TIME_H=1; AC_SUBST([HAVE_SYS_TIME_H])
REPLACE_GETTIMEOFDAY=0; AC_SUBST([REPLACE_GETTIMEOFDAY])
+ REPLACE_STRUCT_TIMEVAL=0; AC_SUBST([REPLACE_STRUCT_TIMEVAL])
])