Mercurial > gnulib
changeset 38516:7c80101595cf
localtime: New module.
* lib/time.in.h (localtime): Declare also if requested by module
'localtime'.
* lib/localtime.c: New file.
* m4/localtime.m4: New file.
* m4/time_h.m4 (gl_HEADER_TIME_H_DEFAULTS): Initialize GNULIB_LOCALTIME.
* modules/time (Makefile.am): Substitute GNULIB_LOCALTIME.
* modules/localtime: New file.
* doc/posix-functions/localtime.texi: Mention the new module.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 30 Apr 2017 13:32:40 +0200 |
parents | 20e94b6fcdaa |
children | 3c138277c7e8 |
files | ChangeLog doc/posix-functions/localtime.texi lib/localtime.c lib/time.in.h m4/localtime.m4 m4/time_h.m4 modules/localtime modules/time |
diffstat | 8 files changed, 105 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Sun Apr 30 13:19:24 2017 +0200 +++ b/ChangeLog Sun Apr 30 13:32:40 2017 +0200 @@ -1,3 +1,15 @@ +2017-04-30 Bruno Haible <bruno@clisp.org> + + localtime: New module. + * lib/time.in.h (localtime): Declare also if requested by module + 'localtime'. + * lib/localtime.c: New file. + * m4/localtime.m4: New file. + * m4/time_h.m4 (gl_HEADER_TIME_H_DEFAULTS): Initialize GNULIB_LOCALTIME. + * modules/time (Makefile.am): Substitute GNULIB_LOCALTIME. + * modules/localtime: New file. + * doc/posix-functions/localtime.texi: Mention the new module. + 2017-04-30 Bruno Haible <bruno@clisp.org> ctime: New module.
--- a/doc/posix-functions/localtime.texi Sun Apr 30 13:19:24 2017 +0200 +++ b/doc/posix-functions/localtime.texi Sun Apr 30 13:32:40 2017 +0200 @@ -4,18 +4,18 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/localtime.html} -Gnulib module: --- +Gnulib module: localtime Portability problems fixed by Gnulib: @itemize +@item +On native Windows platforms (mingw, MSVC), this function works incorrectly +when the environment variable @code{TZ} has been set by Cygwin. @end itemize Portability problems not fixed by Gnulib: @itemize @item -On native Windows platforms (mingw, MSVC), this function works incorrectly -when the environment variable @code{TZ} has been set by Cygwin. -@item On some platforms, this function returns nonsense values for unsupported arguments (like @math{2^56}), rather than failing: FreeBSD 10.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/localtime.c Sun Apr 30 13:32:40 2017 +0200 @@ -0,0 +1,45 @@ +/* Work around platform bugs in localtime. + Copyright (C) 2017 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <config.h> + +/* Specification. */ +#include <time.h> + +/* Keep consistent with gettimeofday.c! */ +#if !(GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME) + +# include <stdlib.h> +# include <string.h> + +# undef localtime + +struct tm * +rpl_localtime (const time_t *tp) +{ +# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + /* If the environment variable TZ has been set by Cygwin, neutralize it. + The Microsoft CRT interprets TZ differently than Cygwin and produces + incorrect results if TZ has the syntax used by Cygwin. */ + const char *tz = getenv ("TZ"); + if (tz != NULL && strchr (tz, '/') != NULL) + _putenv ("TZ="); +# endif + + return localtime (tp); +} + +#endif
--- a/lib/time.in.h Sun Apr 30 13:19:24 2017 +0200 +++ b/lib/time.in.h Sun Apr 30 13:32:40 2017 +0200 @@ -187,7 +187,7 @@ /* Convert TIMER to RESULT, assuming local time and UTC respectively. See <http://www.opengroup.org/susv3xsh/localtime.html> and <http://www.opengroup.org/susv3xsh/gmtime.html>. */ -# if @GNULIB_GETTIMEOFDAY@ +# if @GNULIB_LOCALTIME@ || @GNULIB_GETTIMEOFDAY@ # if @REPLACE_LOCALTIME@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) # undef localtime
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m4/localtime.m4 Sun Apr 30 13:32:40 2017 +0200 @@ -0,0 +1,14 @@ +# localtime.m4 serial 1 +dnl Copyright (C) 2017 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. + +AC_DEFUN([gl_FUNC_LOCALTIME], +[ + AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS]) + AC_REQUIRE([AC_CANONICAL_HOST]) + case "$host_os" in + mingw*) REPLACE_LOCALTIME=1 ;; + esac +])
--- a/m4/time_h.m4 Sun Apr 30 13:19:24 2017 +0200 +++ b/m4/time_h.m4 Sun Apr 30 13:32:40 2017 +0200 @@ -106,6 +106,7 @@ [ GNULIB_CTIME=0; AC_SUBST([GNULIB_CTIME]) GNULIB_MKTIME=0; AC_SUBST([GNULIB_MKTIME]) + GNULIB_LOCALTIME=0; AC_SUBST([GNULIB_LOCALTIME]) GNULIB_NANOSLEEP=0; AC_SUBST([GNULIB_NANOSLEEP]) GNULIB_STRPTIME=0; AC_SUBST([GNULIB_STRPTIME]) GNULIB_TIMEGM=0; AC_SUBST([GNULIB_TIMEGM])
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/localtime Sun Apr 30 13:32:40 2017 +0200 @@ -0,0 +1,27 @@ +Description: +localtime() function: convert time to broken-down local time. + +Files: +lib/localtime.c +m4/localtime.m4 + +Depends-on: +time + +configure.ac: +gl_FUNC_LOCALTIME +if test $REPLACE_LOCALTIME = 1; then + AC_LIBOBJ([localtime]) +fi +gl_TIME_MODULE_INDICATOR([localtime]) + +Makefile.am: + +Include: +<time.h> + +License: +LGPLv2+ + +Maintainer: +all
--- a/modules/time Sun Apr 30 13:19:24 2017 +0200 +++ b/modules/time Sun Apr 30 13:32:40 2017 +0200 @@ -32,6 +32,7 @@ -e 's|@''NEXT_TIME_H''@|$(NEXT_TIME_H)|g' \ -e 's/@''GNULIB_CTIME''@/$(GNULIB_CTIME)/g' \ -e 's/@''GNULIB_GETTIMEOFDAY''@/$(GNULIB_GETTIMEOFDAY)/g' \ + -e 's/@''GNULIB_LOCALTIME''@/$(GNULIB_LOCALTIME)/g' \ -e 's/@''GNULIB_MKTIME''@/$(GNULIB_MKTIME)/g' \ -e 's/@''GNULIB_NANOSLEEP''@/$(GNULIB_NANOSLEEP)/g' \ -e 's/@''GNULIB_STRPTIME''@/$(GNULIB_STRPTIME)/g' \