diff options
author | Simon Josefsson <simon@josefsson.org> | 2007-02-13 16:26:08 +0000 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2007-02-13 16:26:08 +0000 |
commit | 0f9d31c7a6caa9802974ec0376c09e0ae9c6a1aa (patch) | |
tree | 0fb398bcb2da6e99f5cd566136a780c025a9e2d5 /lgl | |
parent | 7f9cdc5c47ca76d7415de6d2bd97795e0d7b6c27 (diff) | |
download | gnutls-0f9d31c7a6caa9802974ec0376c09e0ae9c6a1aa.tar.gz |
Update.
Diffstat (limited to 'lgl')
-rw-r--r-- | lgl/Makefile.am | 27 | ||||
-rw-r--r-- | lgl/m4/gnulib-comp.m4 | 4 | ||||
-rw-r--r-- | lgl/m4/time_h.m4 | 76 | ||||
-rw-r--r-- | lgl/m4/time_r.m4 | 7 | ||||
-rw-r--r-- | lgl/string_.h | 52 | ||||
-rw-r--r-- | lgl/time_.h | 107 | ||||
-rw-r--r-- | lgl/time_r.c | 4 | ||||
-rw-r--r-- | lgl/time_r.h | 52 |
8 files changed, 255 insertions, 74 deletions
diff --git a/lgl/Makefile.am b/lgl/Makefile.am index 12eac7eaa3..02666fe0a5 100644 --- a/lgl/Makefile.am +++ b/lgl/Makefile.am @@ -379,10 +379,35 @@ EXTRA_DIST += stat_.h ## end gnulib module sys_stat +## begin gnulib module time + +BUILT_SOURCES += time.h + +# We need the following in order to create <time.h> when the system +# doesn't have one that works with the given compiler. +time.h: time_.h + rm -f $@-t $@ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ + sed -e 's|@ABSOLUTE_TIME_H''@|$(ABSOLUTE_TIME_H)|g' \ + -e 's|@REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \ + -e 's|@REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \ + -e 's|@REPLACE_STRPTIME''@|$(REPLACE_STRPTIME)|g' \ + -e 's|@REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \ + -e 's|@SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ + -e 's|@TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ + < $(srcdir)/time_.h; \ + } > $@-t + mv $@-t $@ +MOSTLYCLEANFILES += time.h time.h-t + +EXTRA_DIST += time_.h + +## end gnulib module time + ## begin gnulib module time_r -EXTRA_DIST += time_r.c time_r.h +EXTRA_DIST += time_r.c EXTRA_liblgnu_la_SOURCES += time_r.c diff --git a/lgl/m4/gnulib-comp.m4 b/lgl/m4/gnulib-comp.m4 index 63f05212f3..d1026270c1 100644 --- a/lgl/m4/gnulib-comp.m4 +++ b/lgl/m4/gnulib-comp.m4 @@ -86,6 +86,7 @@ AC_DEFUN([lgl_INIT], AC_PROG_MKDIR_P gl_HEADER_SYS_STAT_H AC_PROG_MKDIR_P + gl_HEADER_TIME_H gl_TIME_R gl_HEADER_UNISTD gl_FUNC_VASNPRINTF @@ -180,8 +181,8 @@ AC_DEFUN([lgl_FILE_LIST], [ lib/string_.h lib/strverscmp.c lib/strverscmp.h + lib/time_.h lib/time_r.c - lib/time_r.h lib/unistd_.h lib/vasnprintf.c lib/vasnprintf.h @@ -255,6 +256,7 @@ AC_DEFUN([lgl_FILE_LIST], [ m4/strverscmp.m4 m4/sys_socket_h.m4 m4/sys_stat_h.m4 + m4/time_h.m4 m4/time_r.m4 m4/uintmax_t.m4 m4/ulonglong.m4 diff --git a/lgl/m4/time_h.m4 b/lgl/m4/time_h.m4 new file mode 100644 index 0000000000..e90ed7ac37 --- /dev/null +++ b/lgl/m4/time_h.m4 @@ -0,0 +1,76 @@ +# Configure a more-standard replacement for <time.h>. + +# Copyright (C) 2000, 2001, 2003, 2004, 2005, 2006, 2007 Free Software +# Foundation, Inc. + +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# Written by Paul Eggert and Jim Meyering. + +AC_DEFUN([gl_HEADER_TIME_H], +[ + dnl Use AC_REQUIRE here, so that the default behavior below is expanded + dnl once only, before all statements that occur in other macros. + AC_REQUIRE([gl_HEADER_TIME_H_BODY]) +]) + +AC_DEFUN([gl_HEADER_TIME_H_BODY], +[ + AC_REQUIRE([AC_C_RESTRICT]) + AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS]) + gl_ABSOLUTE_HEADER([time.h]) + ABSOLUTE_TIME_H=\"$gl_cv_absolute_time_h\" + AC_SUBST([ABSOLUTE_TIME_H]) + AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC]) +]) + +AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS], +[ + dnl If another module says to replace or to not replace, do that. + dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK; + dnl this lets maintainers check for portability. + REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R]) + REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP]) + REPLACE_STRPTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_STRPTIME]) + REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM]) +]) + +dnl Define HAVE_STRUCT_TIMESPEC if `struct timespec' is declared +dnl in time.h or sys/time.h. + +AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC], +[ + AC_CHECK_HEADERS_ONCE([sys/time.h]) + AC_CACHE_CHECK([for struct timespec in <time.h>], + [gl_cv_sys_struct_timespec_in_time_h], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include <time.h> + ]], + [[static struct timespec x; x.tv_sec = x.tv_nsec;]])], + [gl_cv_sys_struct_timespec_in_time_h=yes], + [gl_cv_sys_struct_timespec_in_time_h=no])]) + + TIME_H_DEFINES_STRUCT_TIMESPEC=0 + SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0 + if test $gl_cv_sys_struct_timespec_in_time_h = yes; then + TIME_H_DEFINES_STRUCT_TIMESPEC=1 + else + AC_CACHE_CHECK([for struct timespec in <sys/time.h>], + [gl_cv_sys_struct_timespec_in_sys_time_h], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include <sys/time.h> + ]], + [[static struct timespec x; x.tv_sec = x.tv_nsec;]])], + [gl_cv_sys_struct_timespec_in_sys_time_h=yes], + [gl_cv_sys_struct_timespec_in_sys_time_h=no])]) + if test $gl_cv_sys_struct_timespec_in_time_h = yes; then + SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1 + fi + fi + AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC]) + AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC]) +]) diff --git a/lgl/m4/time_r.m4 b/lgl/m4/time_r.m4 index ac8353a569..a4e016f819 100644 --- a/lgl/m4/time_r.m4 +++ b/lgl/m4/time_r.m4 @@ -1,6 +1,6 @@ dnl Reentrant time functions like localtime_r. -dnl Copyright (C) 2003, 2006 Free Software Foundation, Inc. +dnl Copyright (C) 2003, 2006, 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -24,10 +24,9 @@ AC_DEFUN([gl_TIME_R], [gl_cv_time_r_posix=yes], [gl_cv_time_r_posix=no])]) if test $gl_cv_time_r_posix = yes; then - AC_DEFINE([HAVE_TIME_R_POSIX], 1, - [Define to 1 if localtime_r, etc. have the type signatures that - POSIX requires.]) + REPLACE_LOCALTIME_R=0 else + REPLACE_LOCALTIME_R=1 AC_LIBOBJ([time_r]) gl_PREREQ_TIME_R fi diff --git a/lgl/string_.h b/lgl/string_.h index 233a2bfea1..69c8bf5ac8 100644 --- a/lgl/string_.h +++ b/lgl/string_.h @@ -64,7 +64,9 @@ extern void *memmem (void const *__haystack, size_t __haystack_len, # endif #elif defined GNULIB_POSIXCHECK # undef memmem -# define memmem memmem_is_unportable__use_gnulib_module_memmem_for_portability +# define memmem(a,al,b,bl) \ + (GL_LINK_WARNING ("memmem is unportable - use gnulib module memmem for portability"), \ + memmem (a, al, b, bl)) #endif /* Copy N bytes of SRC to DEST, return pointer to bytes after the @@ -76,7 +78,9 @@ extern void *mempcpy (void *restrict __dest, void const *restrict __src, # endif #elif defined GNULIB_POSIXCHECK # undef mempcpy -# define mempcpy mempcpy_is_unportable__use_gnulib_module_mempcpy_for_portability +# define mempcpy(a,b,n) \ + (GL_LINK_WARNING ("mempcpy is unportable - use gnulib module mempcpy for portability"), \ + mempcpy (a, b, n)) #endif /* Search backwards through a block for a byte (specified as an int). */ @@ -86,7 +90,9 @@ extern void *memrchr (void const *, int, size_t); # endif #elif defined GNULIB_POSIXCHECK # undef memrchr -# define memrchr memrchr_is_unportable__use_gnulib_module_memrchr_for_portability +# define memrchr(a,b,c) \ + (GL_LINK_WARNING ("memrchr is unportable - use gnulib module memrchr for portability"), \ + memrchr (a, b, c)) #endif /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */ @@ -96,7 +102,9 @@ extern char *stpcpy (char *restrict __dst, char const *restrict __src); # endif #elif defined GNULIB_POSIXCHECK # undef stpcpy -# define stpcpy stpcpy_is_unportable__use_gnulib_module_stpcpy_for_portability +# define stpcpy(a,b) \ + (GL_LINK_WARNING ("stpcpy is unportable - use gnulib module stpcpy for portability"), \ + stpcpy (a, b)) #endif /* Copy no more than N bytes of SRC to DST, returning a pointer past the @@ -109,7 +117,9 @@ extern char *stpncpy (char *restrict __dst, char const *restrict __src, # endif #elif defined GNULIB_POSIXCHECK # undef stpncpy -# define stpncpy stpncpy_is_unportable__use_gnulib_module_stpncpy_for_portability +# define stpncpy(a,b,n) \ + (GL_LINK_WARNING ("stpncpy is unportable - use gnulib module stpncpy for portability"), \ + stpncpy (a, b, n)) #endif /* Compare strings S1 and S2, ignoring case, returning less than, equal to or @@ -141,9 +151,9 @@ extern int strncasecmp (char const *s1, char const *s2, size_t n); POSIX says that it operates on "strings", and "string" in POSIX is defined as a sequence of bytes, not of characters. */ # undef strncasecmp -# define strncasecmp(a,b) \ +# define strncasecmp(a,b,n) \ (GL_LINK_WARNING ("strncasecmp cannot work correctly on character strings in multibyte locales - don't use it if you care about internationalization; use c_strncasecmp (from gnulib module c-strcase) if you want a locale independent function"), \ - strncasecmp (a, b)) + strncasecmp (a, b, n)) #endif #if defined GNULIB_POSIXCHECK @@ -162,7 +172,9 @@ extern char *strchrnul (char const *__s, int __c_in); # endif #elif defined GNULIB_POSIXCHECK # undef strchrnul -# define strchrnul strchrnul_is_unportable__use_gnulib_module_strchrnul_for_portability +# define strchrnul(a,b) \ + (GL_LINK_WARNING ("strchrnul is unportable - use gnulib module strchrnul for portability"), \ + strchrnul (a, b)) #endif /* Duplicate S, returning an identical malloc'd string. */ @@ -172,7 +184,9 @@ extern char *strdup (char const *__s); # endif #elif defined GNULIB_POSIXCHECK # undef strdup -# define strdup strdup_is_unportable__use_gnulib_module_strdup_for_portability +# define strdup(a) \ + (GL_LINK_WARNING ("strdup is unportable - use gnulib module strdup for portability"), \ + strdup (a)) #endif /* Return a newly allocated copy of at most N bytes of STRING. */ @@ -186,7 +200,9 @@ extern char *strndup (char const *__string, size_t __n); # endif #elif defined GNULIB_POSIXCHECK # undef strndup -# define strndup strndup_is_unportable__use_gnulib_module_strndup_for_portability +# define strndup(a,n) \ + (GL_LINK_WARNING ("strndup is unportable - use gnulib module strndup for portability"), \ + strndup (a, n)) #endif /* Find the length (number of bytes) of STRING, but scan at most @@ -198,7 +214,9 @@ extern size_t strnlen (char const *__string, size_t __maxlen); # endif #elif defined GNULIB_POSIXCHECK # undef strnlen -# define strnlen strnlen_is_unportable__use_gnulib_module_strnlen_for_portability +# define strnlen(a,n) \ + (GL_LINK_WARNING ("strnlen is unportable - use gnulib module strnlen for portability"), \ + strnlen (a, n)) #endif #if defined GNULIB_POSIXCHECK @@ -229,7 +247,9 @@ extern char *strpbrk (char const *__s, char const *__accept); # endif #elif defined GNULIB_POSIXCHECK # undef strpbrk -# define strpbrk strpbrk_is_unportable__use_gnulib_module_strpbrk_for_portability +# define strpbrk(s,a) \ + (GL_LINK_WARNING ("strpbrk is unportable - use gnulib module strpbrk for portability"), \ + strpbrk (s, a)) #endif #if defined GNULIB_POSIXCHECK @@ -278,7 +298,9 @@ extern char *strsep (char **restrict __stringp, char const *restrict __delim); # endif #elif defined GNULIB_POSIXCHECK # undef strsep -# define strsep strsep_is_unportable__use_gnulib_module_strsep_for_portability +# define strsep(s,d) \ + (GL_LINK_WARNING ("strsep is unportable - use gnulib module strsep for portability"), \ + strsep (s, d)) #endif #if defined GNULIB_POSIXCHECK @@ -342,7 +364,9 @@ extern char *strtok_r (char *restrict s, char const *restrict delim, # endif #elif defined GNULIB_POSIXCHECK # undef strtok_r -# define strtok_r strtok_r_is_unportable__use_gnulib_module_strtok_r_for_portability +# define strtok_r(s,d,p) \ + (GL_LINK_WARNING ("strtok_r is unportable - use gnulib module strtok_r for portability"), \ + strtok_r (s, d, p)) #endif diff --git a/lgl/time_.h b/lgl/time_.h new file mode 100644 index 0000000000..b4709bf85f --- /dev/null +++ b/lgl/time_.h @@ -0,0 +1,107 @@ +/* A more-standard <time.h>. + + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Don't get in the way of glibc when it includes time.h merely to + declare a few standard symbols, rather than to declare all the + symbols. */ +#if defined __need_time_t || defined __need_clock_t || defined __need_timespec +# include @ABSOLUTE_TIME_H@ + +#elif ! defined _GL_TIME_H +# define _GL_TIME_H +# include @ABSOLUTE_TIME_H@ + +# ifdef __cplusplus +extern "C" { +# endif + +/* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3). + Or they define it with the wrong member names or define it in <sys/time.h> + (e.g., FreeBSD circa 1997). */ +# if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@ +# if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@ +# include <sys/time.h> +# else +# undef timespec +# define timespec rpl_timespec +struct timespec +{ + time_t tv_sec; + long int tv_nsec; +}; +# endif +# endif + +/* Sleep for at least RQTP seconds unless interrupted, If interrupted, + return -1 and store the remaining time into RMTP. See + <http://www.opengroup.org/susv3xsh/nanosleep.html>. */ +# if @REPLACE_NANOSLEEP@ +# define nanosleep rpl_nanosleep +int nanosleep (struct timespec const *__rqtp, struct timespec *__rmtp); +# endif + +/* Convert TIMER to RESULT, assuming local time and UTC respectively. See + <http://www.opengroup.org/susv3xsh/localtime_r.html> and + <http://www.opengroup.org/susv3xsh/gmtime_r.html>. */ +# if @REPLACE_LOCALTIME_R@ +# undef localtime_r +# define localtime_r rpl_localtime_r +# undef gmtime_r +# define gmtime_r rpl_gmtime_r +struct tm *localtime_r (time_t const *restrict __timer, + struct tm *restrict __result); +struct tm *gmtime_r (time_t const *restrict __timer, + struct tm *restrict __result); +# endif + +/* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store + the resulting broken-down time into TM. See + <http://www.opengroup.org/susv3xsh/strptime.html>. */ +# if @REPLACE_STRPTIME@ +# undef strptime +# define strptime rpl_strptime +char *strptime (char const *restrict __buf, char const *restrict __format, + struct tm *restrict __tm); +# endif + +/* Convert TM to a time_t value, assuming UTC. */ +# if @REPLACE_TIMEGM@ +# undef timegm +# define timegm rpl_timegm +time_t timegm (struct tm *__tm); +#endif + +/* Encourage applications to avoid unsafe functions that can overrrun + buffers when given outlandish struct tm values. Portable + applications should use strftime (or even sprintf) instead. */ +# if GNULIB_PORTCHECK +# undef asctime +# define asctime eschew_asctime +# undef asctime_r +# define asctime_r eschew_asctime_r +# undef ctime +# define ctime eschew_ctime +# undef ctime_r +# define ctime_r eschew_ctime_r +# endif + +# ifdef __cplusplus +} +# endif + +#endif diff --git a/lgl/time_r.c b/lgl/time_r.c index b1469b0cac..7317195e30 100644 --- a/lgl/time_r.c +++ b/lgl/time_r.c @@ -1,6 +1,6 @@ /* Reentrant time functions like localtime_r. - Copyright (C) 2003, 2006 Free Software Foundation, Inc. + Copyright (C) 2003, 2006, 2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -20,7 +20,7 @@ #include <config.h> -#include "time_r.h" +#include <time.h> #include <string.h> diff --git a/lgl/time_r.h b/lgl/time_r.h deleted file mode 100644 index 8f91947ab4..0000000000 --- a/lgl/time_r.h +++ /dev/null @@ -1,52 +0,0 @@ -/* Reentrant time functions like localtime_r. - - Copyright (C) 2003, 2005, 2006 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2.1, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along - with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -/* Written by Paul Eggert. */ - -#ifndef _TIME_R_H -#define _TIME_R_H - -/* Include <time.h> first, since it may declare these functions with - signatures that disagree with POSIX, and we don't want to rename - those declarations. */ -#include <time.h> - -#if !HAVE_TIME_R_POSIX - -/* Don't bother with asctime_r and ctime_r, since these functions are - not safe (like asctime and ctime, they can overrun their 26-byte - output buffers when given outlandish struct tm values), and we - don't want to encourage applications to use unsafe functions. Use - strftime or even sprintf instead. */ - -# undef gmtime_r -# undef localtime_r - -# define gmtime_r rpl_gmtime_r -# define localtime_r rpl_localtime_r - -/* See the POSIX:2001 specification - <http://www.opengroup.org/susv3xsh/gmtime.html>. */ -struct tm *gmtime_r (time_t const * restrict, struct tm * restrict); - -/* See the POSIX:2001 specification - <http://www.opengroup.org/susv3xsh/localtime.html>. */ -struct tm *localtime_r (time_t const * restrict, struct tm * restrict); -#endif - -#endif |