sys_time: allow too-wide tv_sec
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 6 Jul 2012 02:28:29 +0000 (02:28 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 6 Jul 2012 02:28:29 +0000 (02:28 +0000)
* m4/sys_time_h.m4 (gl_HEADER_SYS_TIME_H_BODY): Allow struct
timeval even if tv_sec is wider than time_t.  This allows
OpenBSD 5.1 amd64 and fixes an Emacs porting glitch with utimens.c,
as without this patch gnulib replaces struct timeval
and OpenBSD futimes therefore has a type mismatch.
* doc/posix-headers/sys_time.texi: Mention this.

ChangeLog
doc/posix-headers/sys_time.texi
m4/sys_time_h.m4

index 78b2ab3..590bcc1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2012-07-05  Paul Eggert  <eggert@cs.ucla.edu>
 
+       sys_time: allow too-wide tv_sec
+       * m4/sys_time_h.m4 (gl_HEADER_SYS_TIME_H_BODY): Allow struct
+       timeval even if tv_sec is wider than time_t.  This allows
+       OpenBSD 5.1 amd64 and fixes an Emacs porting glitch with utimens.c,
+       as without this patch gnulib replaces struct timeval
+       and OpenBSD futimes therefore has a type mismatch.
+       * doc/posix-headers/sys_time.texi: Mention this.
+
        pthread: check for both pthread_create and pthread_join
        * m4/pthread.m4 (gl_PTHREAD_CHECK): Revert previous change, but
        alter the check so that it tests for both pthread_create and
index 6650b7e..2cacaa5 100644 (file)
@@ -13,7 +13,8 @@ MSVC 9.
 @item
 @samp{struct timeval} is not defined on some platforms.
 @item
-@samp{struct timeval} is defined with an incompatible type for @code{tv_sec}
+@samp{struct timeval} is defined with a @code{tv_sec} type that is
+narrower than @code{time_t}
 on some native Windows platforms:
 mingw64 in 64-bit mode,
 mingw64 in 32-bit mode when @code{__MINGW_USE_VC2005_COMPAT} is defined,
@@ -23,4 +24,8 @@ MSVC 9 in 32-bit mode when @code{_USE_32BIT_TIME_T} is not defined.
 
 Portability problems not fixed by Gnulib:
 @itemize
+@item
+@samp{struct timeval} is defined with a @code{tv_sec} type that is
+wider than @code{time_t}:
+OpenBSD 5.1 in 64-bit mode.
 @end itemize
index 26eaf8e..c4a30cd 100644 (file)
@@ -52,7 +52,9 @@ AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY],
     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],
+    dnl On OpenBSD 5.1 amd64, tv_sec is 64 bits and time_t 32 bits, but
+    dnl that is good enough.
+    AC_CACHE_CHECK([for wide-enough struct timeval.tv_sec member],
       [gl_cv_sys_struct_timeval_tv_sec],
       [AC_COMPILE_IFELSE(
          [AC_LANG_PROGRAM(
@@ -65,7 +67,9 @@ AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY],
               #endif
             ]],
             [[static struct timeval x;
-              typedef int verify_tv_sec_type[sizeof (x.tv_sec) == sizeof (time_t) ? 1 : -1];
+              typedef int verify_tv_sec_type[
+                sizeof (time_t) <= sizeof x.tv_sec ? 1 : -1
+              ];
             ]])],
          [gl_cv_sys_struct_timeval_tv_sec=yes],
          [gl_cv_sys_struct_timeval_tv_sec=no])