git: a34940a9756a - main - timezone: Move to the XSI/POSIX definition for timezone.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 12 Mar 2024 04:19:43 UTC
The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=a34940a9756ac8edce36fec176949ee82e9235b4 commit a34940a9756ac8edce36fec176949ee82e9235b4 Author: Warner Losh <imp@FreeBSD.org> AuthorDate: 2024-03-12 04:19:05 +0000 Commit: Warner Losh <imp@FreeBSD.org> CommitDate: 2024-03-12 04:19:31 +0000 timezone: Move to the XSI/POSIX definition for timezone. The old timezone(3) function has long since been obsolete and has a fatally flawed interface. Retain this function for compatibility purposes, but shift to providing the offset from UTC in the timezone variable, whether or not the timezone observes summer time in the 'daylight' variable. Document the tzname variable that's already been set. Also make _tztab() static. It's not used in libc (or anywhere in the tree) and it's not exported as a public dynamic symbol. Sponsored by: Netflix Reviewed by: brooks, kib Differential Revision: https://reviews.freebsd.org/D44281 --- contrib/tzcode/tzconfig.h | 2 +- include/time.h | 3 ++- lib/libc/gen/Makefile.inc | 3 ++- lib/libc/gen/Symbol.map | 1 - lib/libc/gen/timezone.3 | 66 --------------------------------------------- lib/libc/gen/timezone.c | 7 ++--- lib/libc/gen/tzset.3 | 23 +++++++++++++++- lib/libc/stdtime/Symbol.map | 5 ++++ 8 files changed, 36 insertions(+), 74 deletions(-) diff --git a/contrib/tzcode/tzconfig.h b/contrib/tzcode/tzconfig.h index 730043b36526..c692d06953a2 100644 --- a/contrib/tzcode/tzconfig.h +++ b/contrib/tzcode/tzconfig.h @@ -13,7 +13,7 @@ #define NETBSD_INSPIRED 0 #define STD_INSPIRED 1 #define HAVE_TZNAME 2 -#define USG_COMPAT 0 +#define USG_COMPAT 2 #define ALTZONE 0 #endif /* !TZCONFIG_H_INCLUDED */ diff --git a/include/time.h b/include/time.h index 0ba685426f82..defad96907bf 100644 --- a/include/time.h +++ b/include/time.h @@ -162,10 +162,11 @@ struct tm *localtime_r(const time_t *, struct tm *); #if __XSI_VISIBLE char *strptime(const char * __restrict, const char * __restrict, struct tm * __restrict); +extern long timezone; +extern int daylight; #endif #if __BSD_VISIBLE -char *timezone(int, int); /* XXX XSI conflict */ time_t timelocal(struct tm * const); time_t timegm(struct tm * const); int timer_oshandle_np(timer_t timerid); diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index 3a8b4e57420a..9c79cd589395 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -307,7 +307,6 @@ MAN+= alarm.3 \ times.3 \ timespec_get.3 \ timespec_getres.3 \ - timezone.3 \ ttyname.3 \ tzset.3 \ ualarm.3 \ @@ -535,6 +534,8 @@ MLINKS+=tcsetattr.3 cfgetispeed.3 \ tcsetattr.3 tcgetattr.3 MLINKS+=ttyname.3 isatty.3 \ ttyname.3 ttyname_r.3 +MLINKS+=tzset.3 daylight.3 \ + tzset.3 timezone.3 MLINKS+=unvis.3 strunvis.3 \ unvis.3 strunvisx.3 MLINKS+=vis.3 nvis.3 \ diff --git a/lib/libc/gen/Symbol.map b/lib/libc/gen/Symbol.map index 0c58411168af..43d9c36c789e 100644 --- a/lib/libc/gen/Symbol.map +++ b/lib/libc/gen/Symbol.map @@ -261,7 +261,6 @@ FBSD_1.0 { setlogmask; ttyname_r; ttyname; - timezone; times; time; telldir; diff --git a/lib/libc/gen/timezone.3 b/lib/libc/gen/timezone.3 deleted file mode 100644 index e469f18346bf..000000000000 --- a/lib/libc/gen/timezone.3 +++ /dev/null @@ -1,66 +0,0 @@ -.\" Copyright (c) 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.Dd April 19, 1994 -.Dt TIMEZONE 3 -.Os -.Sh NAME -.Nm timezone -.Nd return the timezone abbreviation -.Sh LIBRARY -.Lb libc -.Sh SYNOPSIS -.Ft char * -.Fn timezone "int zone" "int dst" -.Sh DESCRIPTION -.Bf Sy -This interface is for compatibility only; it is impossible to reliably -map timezone's arguments to a time zone abbreviation. -See -.Xr ctime 3 . -.Ef -.Pp -The -.Fn timezone -function returns a pointer to a time zone abbreviation for the specified -.Fa zone -and -.Fa dst -values. -The -.Fa zone -argument -is the number of minutes west of GMT and -.Fa dst -is non-zero if daylight savings time is in effect. -.Sh SEE ALSO -.Xr ctime 3 -.Sh HISTORY -A -.Fn timezone -function appeared in -.At v7 . diff --git a/lib/libc/gen/timezone.c b/lib/libc/gen/timezone.c index 1adc9aa1e988..2809067eb8d8 100644 --- a/lib/libc/gen/timezone.c +++ b/lib/libc/gen/timezone.c @@ -36,7 +36,7 @@ #include <string.h> #define TZ_MAX_CHARS 255 -char *_tztab(int, int); +static char *_tztab(int, int); /* * timezone -- @@ -49,7 +49,7 @@ char *_tztab(int, int); static char czone[TZ_MAX_CHARS]; /* space for zone name */ char * -timezone(int zone, int dst) +__timezone_compat(int zone, int dst) { char *beg, *end; @@ -68,6 +68,7 @@ timezone(int zone, int dst) } return(_tztab(zone,dst)); /* default: table or created zone */ } +__sym_compat(timezone, __timezone_compat, FBSD_1.0); static struct zone { int offset; @@ -99,7 +100,7 @@ static struct zone { * aren't in place in /etc. DO NOT USE THIS ROUTINE OUTSIDE OF THE * STANDARD LIBRARY. */ -char * +static char * _tztab(int zone, int dst) { struct zone *zp; diff --git a/lib/libc/gen/tzset.3 b/lib/libc/gen/tzset.3 index 1207818d4057..94ccbec9aba7 100644 --- a/lib/libc/gen/tzset.3 +++ b/lib/libc/gen/tzset.3 @@ -28,16 +28,22 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd March 6, 2023 +.Dd December 25, 2023 .Dt TZSET 3 .Os .Sh NAME +.Nm daylight , +.Nm timezone , +.Nm tzname , .Nm tzset .Nd initialize time conversion information .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In time.h +.Vt extern int daylight ; +.Vt extern long timezone ; +.Vt extern char *tzname[2] ; .Ft void .Fn tzset void .Sh DESCRIPTION @@ -93,6 +99,21 @@ environment variable does not specify a file and cannot be interpreted as a direct specification, .Tn UTC is used. +.Pp +After the first call to +.Nm tzset , +the +.Vt timezone +variable is set to the difference, in seconds, between Coordinated Universal +Time (UTC) and the local time. +The +.Vt daylight +variable is set to 0 if the local timezone is observing standard time. +It is set to 1 if the local timezone ever observes an alternate time, such as summer time. +The first element of the +.Vt tzname +array is the timezone name of standard time, while the second element is the +name of the altnerative time zone. .Sh SPECIFICATION FORMAT When .Ev TZ diff --git a/lib/libc/stdtime/Symbol.map b/lib/libc/stdtime/Symbol.map index 0dca02903a1a..669d4d47907b 100644 --- a/lib/libc/stdtime/Symbol.map +++ b/lib/libc/stdtime/Symbol.map @@ -30,3 +30,8 @@ FBSD_1.0 { asctime_r; asctime; }; + +FBSD_1.8 { + daylight; + timezone; +};