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
This commit is contained in:
Warner Losh 2024-03-11 22:19:05 -06:00
parent 7b133b34f8
commit a34940a975
8 changed files with 36 additions and 74 deletions

View File

@ -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 */

View File

@ -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);

View File

@ -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 \

View File

@ -261,7 +261,6 @@ FBSD_1.0 {
setlogmask;
ttyname_r;
ttyname;
timezone;
times;
time;
telldir;

View File

@ -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 .

View File

@ -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;

View File

@ -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

View File

@ -30,3 +30,8 @@ FBSD_1.0 {
asctime_r;
asctime;
};
FBSD_1.8 {
daylight;
timezone;
};