mirror of
https://git.savannah.gnu.org/git/gnulib.git
synced 2025-08-17 12:41:05 +03:00
gettimeofday: expose type of second argument
Needed to silence compiler warnings such as: test-gettimeofday.c:23: warning: initialization from incompatible pointer type based on whether gettimeofday complies with POSIX or provides the extension of struct timezone. * m4/gettimeofday.m4 (gl_FUNC_GETTIMEOFDAY): Do better detection of glibc extension signature, and define GETTIMEOFDAY_TIMEZONE. * tests/test-gettimeofday.c: Use it to silence warning. * doc/posix-functions/gettimeofday.texi (gettimeofday): Document the issue. Signed-off-by: Eric Blake <ebb9@byu.net>
This commit is contained in:
@@ -1,3 +1,12 @@
|
|||||||
|
2010-02-04 Eric Blake <ebb9@byu.net>
|
||||||
|
|
||||||
|
gettimeofday: expose type of second argument
|
||||||
|
* m4/gettimeofday.m4 (gl_FUNC_GETTIMEOFDAY): Do better detection
|
||||||
|
of glibc extension signature, and define GETTIMEOFDAY_TIMEZONE.
|
||||||
|
* tests/test-gettimeofday.c: Use it to silence warning.
|
||||||
|
* doc/posix-functions/gettimeofday.texi (gettimeofday): Document
|
||||||
|
the issue.
|
||||||
|
|
||||||
2010-02-03 Jim Meyering <meyering@redhat.com>
|
2010-02-03 Jim Meyering <meyering@redhat.com>
|
||||||
|
|
||||||
regcomp.c: avoid the sole warning from gcc's -Wtype-limits
|
regcomp.c: avoid the sole warning from gcc's -Wtype-limits
|
||||||
|
@@ -15,6 +15,15 @@ mingw.
|
|||||||
This function is declared with a nonstandard function prototype (only one
|
This function is declared with a nonstandard function prototype (only one
|
||||||
argument, or ``...'' after the first argument) on some platforms.
|
argument, or ``...'' after the first argument) on some platforms.
|
||||||
@item
|
@item
|
||||||
|
On some platforms, the second argument has type @code{struct
|
||||||
|
timezone*} rather than @code{void *}, making it an error to redeclare
|
||||||
|
the function with the POSIX signature:
|
||||||
|
glibc.
|
||||||
|
However, rather than penalize these systems with a replacement
|
||||||
|
function, gnulib defines @code{GETTIMEOFDAY_TIMEZONE} to the
|
||||||
|
appropriate type for use in avoiding a compiler warning if assigning
|
||||||
|
@code{gettimeofday} to a function pointer.
|
||||||
|
@item
|
||||||
On some platforms, @code{gettimeofday} clobbers the buffer in which
|
On some platforms, @code{gettimeofday} clobbers the buffer in which
|
||||||
@code{localtime} returns its result:
|
@code{localtime} returns its result:
|
||||||
MacOS X 10.0.
|
MacOS X 10.0.
|
||||||
@@ -22,4 +31,7 @@ MacOS X 10.0.
|
|||||||
|
|
||||||
Portability problems not fixed by Gnulib:
|
Portability problems not fixed by Gnulib:
|
||||||
@itemize
|
@itemize
|
||||||
|
@item
|
||||||
|
Behavior is non-portable if the second argument to @code{gettimeofday}
|
||||||
|
is not @code{NULL}.
|
||||||
@end itemize
|
@end itemize
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
# serial 13
|
# serial 14
|
||||||
|
|
||||||
# Copyright (C) 2001-2003, 2005, 2007, 2009-2010 Free Software Foundation, Inc.
|
# Copyright (C) 2001-2003, 2005, 2007, 2009-2010 Free Software Foundation, Inc.
|
||||||
# This file is free software; the Free Software Foundation
|
# This file is free software; the Free Software Foundation
|
||||||
@@ -14,30 +14,46 @@ AC_DEFUN([gl_FUNC_GETTIMEOFDAY],
|
|||||||
AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
|
AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
|
||||||
AC_CHECK_FUNCS_ONCE([gettimeofday])
|
AC_CHECK_FUNCS_ONCE([gettimeofday])
|
||||||
|
|
||||||
|
gl_gettimeofday_timezone=void
|
||||||
|
if test $ac_cv_func_gettimeofday = yes; then
|
||||||
|
gl_FUNC_GETTIMEOFDAY_CLOBBER
|
||||||
AC_CACHE_CHECK([for gettimeofday with POSIX signature],
|
AC_CACHE_CHECK([for gettimeofday with POSIX signature],
|
||||||
[gl_cv_func_gettimeofday_posix_signature],
|
[gl_cv_func_gettimeofday_posix_signature],
|
||||||
[AC_COMPILE_IFELSE(
|
[AC_COMPILE_IFELSE(
|
||||||
[AC_LANG_PROGRAM(
|
[AC_LANG_PROGRAM(
|
||||||
[[#include <sys/time.h>
|
[[#include <sys/time.h>
|
||||||
struct timeval c;
|
struct timeval c;
|
||||||
|
int gettimeofday (struct timeval *restrict, void *restrict);
|
||||||
]],
|
]],
|
||||||
[[
|
[[/* glibc uses struct timezone * rather than the POSIX void *
|
||||||
int (*f) (struct timeval *restrict, void *restrict) = gettimeofday;
|
if _GNU_SOURCE is defined. However, since the only portable
|
||||||
|
use of gettimeofday uses NULL as the second parameter, and
|
||||||
|
since the glibc definition is actually more typesafe, it is
|
||||||
|
not worth wrapping this to get a compliant signature. */
|
||||||
|
int (*f) (struct timeval *restrict, void *restrict)
|
||||||
|
= gettimeofday;
|
||||||
int x = f (&c, 0);
|
int x = f (&c, 0);
|
||||||
return !(x | c.tv_sec | c.tv_usec);
|
return !(x | c.tv_sec | c.tv_usec);
|
||||||
]])],
|
]])],
|
||||||
[gl_cv_func_gettimeofday_posix_signature=yes],
|
[gl_cv_func_gettimeofday_posix_signature=yes],
|
||||||
[gl_cv_func_gettimeofday_posix_signature=no])])
|
[AC_COMPILE_IFELSE(
|
||||||
|
[AC_LANG_PROGRAM(
|
||||||
gl_FUNC_GETTIMEOFDAY_CLOBBER
|
[[#include <sys/time.h>
|
||||||
|
int gettimeofday (struct timeval *restrict, struct timezone *restrict);
|
||||||
if test $gl_cv_func_gettimeofday_posix_signature != yes; then
|
]])],
|
||||||
|
[gl_cv_func_gettimeofday_posix_signature=almost],
|
||||||
|
[gl_cv_func_gettimeofday_posix_signature=no])])])
|
||||||
|
if test $gl_cv_func_gettimeofday_posix_signature = almost; then
|
||||||
|
gl_gettimeofday_timezone='struct timezone'
|
||||||
|
elif test $gl_cv_func_gettimeofday_posix_signature != yes; then
|
||||||
REPLACE_GETTIMEOFDAY=1
|
REPLACE_GETTIMEOFDAY=1
|
||||||
if test $gl_cv_func_gettimeofday_clobber != yes; then
|
|
||||||
AC_LIBOBJ([gettimeofday])
|
AC_LIBOBJ([gettimeofday])
|
||||||
gl_PREREQ_GETTIMEOFDAY
|
gl_PREREQ_GETTIMEOFDAY
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
AC_DEFINE_UNQUOTED([GETTIMEOFDAY_TIMEZONE], [$gl_gettimeofday_timezone],
|
||||||
|
[Define this to 'void' or 'struct timezone' to match the system's
|
||||||
|
declaration of the second argument to gettimeofday.])
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
@@ -20,7 +20,8 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
#include "signature.h"
|
#include "signature.h"
|
||||||
SIGNATURE_CHECK (gettimeofday, int, (struct timeval *, void *));
|
SIGNATURE_CHECK (gettimeofday, int,
|
||||||
|
(struct timeval *, GETTIMEOFDAY_TIMEZONE *));
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
@@ -42,8 +43,5 @@ main (void)
|
|||||||
fprintf (stderr, "gettimeofday still clobbers the localtime buffer!\n");
|
fprintf (stderr, "gettimeofday still clobbers the localtime buffer!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user