From 50df7d69f3af5dbb210326b0b25257e48d11983b Mon Sep 17 00:00:00 2001
From: Paul Eggert
Date: Tue, 19 Jul 2022 10:20:09 -0700
Subject: [PATCH 1/3] gmtime etc. now say "UTC", not "GMT"
POSIX is being revised to require this.
* NEWS, etcetera, theory.html: Mention this.
* date.c (dogmt): Simulate gmtime with TZ=UTC0, not GMT0.
* localtime.c (etc_utc): New constant.
(utc): Now an offset from etc_utc, replacing gmt. All uses changed.
(gmtload): Load from "Etc/UTC", not from "GMT", so that
the abbreviation is "UTC" not "GMT".
---
NEWS | 3 +++
date.c | 4 ++--
etcetera | 8 ++++++--
localtime.c | 15 ++++++++-------
theory.html | 8 ++++++--
5 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/NEWS b/NEWS
index 850e38b..dcb381a 100644
--- a/NEWS
+++ b/NEWS
@@ -48,6 +48,9 @@ Unreleased, experimental changes
zic now checks its input for NUL bytes and unterminated lines, and
now supports input line lengths up to 2048 (not 512) bytes.
+ gmtime and related code now use the abbreviation "UTC" not "GMT".
+ POSIX is being revised to require this.
+
When tzset and related functions set vestigial static variables
like tzname, they now prefer specified timestamps to unspecified ones.
(Problem reported by Almaz Mingaleev.)
diff --git a/date.c b/date.c
index 56e6c87..4e4b355 100644
--- a/date.c
+++ b/date.c
@@ -120,7 +120,7 @@ dogmt(void)
register int from;
register int to;
register int n;
- static char tzegmt0[] = "TZ=GMT0";
+ static char tzeutc0[] = "TZ=UTC0";
for (n = 0; environ[n] != NULL; ++n)
continue;
@@ -131,7 +131,7 @@ dogmt(void)
exit(retval);
}
to = 0;
- fakeenv[to++] = tzegmt0;
+ fakeenv[to++] = tzeutc0;
for (from = 1; environ[from] != NULL; ++from)
if (strncmp(environ[from], "TZ=", 3) != 0)
fakeenv[to++] = environ[from];
diff --git a/etcetera b/etcetera
index 1dc7411..a7e0eb4 100644
--- a/etcetera
+++ b/etcetera
@@ -17,12 +17,16 @@
# behind GMT but uses the completely misleading abbreviation "GMT".
Zone Etc/GMT 0 - GMT
+
+# The following zone is used by tzcode functions like gmtime,
+# which load the "UTC" file to handle seconds properly.
Zone Etc/UTC 0 - UTC
# The following link uses older naming conventions,
# but it belongs here, not in the file 'backward',
-# as functions like gmtime load the "GMT" file to handle leap seconds properly.
-# We want this to work even on installations that omit the other older names.
+# as it is needed for tzcode releases through 2022a,
+# where functions like gmtime load "GMT" instead of the "Etc/UTC".
+# We want this to work even on installations that omit 'backward'.
Link Etc/GMT GMT
Link Etc/UTC Etc/Universal
diff --git a/localtime.c b/localtime.c
index 7de9d9d..073b096 100644
--- a/localtime.c
+++ b/localtime.c
@@ -74,7 +74,8 @@ static void unlock(void) { }
static const char wildabbr[] = WILDABBR;
-static const char gmt[] = "GMT";
+static char const etc_utc[] = "Etc/UTC";
+static char const *utc = etc_utc + sizeof "Etc/" - 1;
/*
** The DST rules to use if TZ has no rules and we can't load TZDEFRULES.
@@ -125,7 +126,7 @@ struct state {
time_t ats[TZ_MAX_TIMES];
unsigned char types[TZ_MAX_TIMES];
struct ttinfo ttis[TZ_MAX_TYPES];
- char chars[max(max(TZ_MAX_CHARS + CHARS_EXTRA, sizeof gmt),
+ char chars[max(max(TZ_MAX_CHARS + CHARS_EXTRA, sizeof "UTC"),
2 * (MY_TZNAME_MAX + 1))];
struct lsinfo lsis[TZ_MAX_LEAPS];
@@ -314,7 +315,7 @@ settzname(void)
int stddst_mask = 0;
#if HAVE_TZNAME
- tzname[0] = tzname[1] = (char *) (sp ? wildabbr : gmt);
+ tzname[0] = tzname[1] = (char *) (sp ? wildabbr : utc);
stddst_mask = 3;
#endif
#if USG_COMPAT
@@ -1393,8 +1394,8 @@ tzparse(const char *name, struct state *sp, struct state *basep)
static void
gmtload(struct state *const sp)
{
- if (tzload(gmt, sp, true) != 0)
- tzparse("GMT0", sp, NULL);
+ if (tzload(etc_utc, sp, true) != 0)
+ tzparse("UTC0", sp, NULL);
}
/* Initialize *SP to a value appropriate for the TZ setting NAME.
@@ -1412,7 +1413,7 @@ zoneinit(struct state *sp, char const *name)
sp->charcnt = 0;
sp->goback = sp->goahead = false;
init_ttinfo(&sp->ttis[0], 0, false, 0);
- strcpy(sp->chars, gmt);
+ strcpy(sp->chars, utc);
sp->defaulttype = 0;
return 0;
} else {
@@ -1666,7 +1667,7 @@ gmtsub(struct state const *sp, time_t const *timep, int_fast32_t offset,
** but this is no time for a treasure hunt.
*/
tmp->TM_ZONE = ((char *)
- (offset ? wildabbr : gmtptr ? gmtptr->chars : gmt));
+ (offset ? wildabbr : gmtptr ? gmtptr->chars : utc));
#endif /* defined TM_ZONE */
return result;
}
diff --git a/theory.html b/theory.html
index 22cd36d..bfadc4f 100644
--- a/theory.html
+++ b/theory.html
@@ -376,9 +376,11 @@ The source file etcetera
defines names that may be useful
on platforms that do not support POSIX-style TZ
strings;
no other source file other than backward
contains links to its zones.
-One of etcetera
's names is GMT
,
+One of etcetera
's names is Etc/UTC
,
used by functions like gmtime
to obtain leap
second information on platforms that support leap seconds.
+Another etcetera
name, GMT
,
+is used by older code releases.
@@ -468,6 +470,7 @@ in decreasing order of importance:
PST/PDT Philippine,
SAST South Africa,
SST Samoa,
+ UTC Universal,
WAT/WAST West Africa,
WET/WEST/WEMT Western European,
WIB Waktu Indonesia Barat,
@@ -1295,7 +1298,8 @@ Because a leap second adjustment may be needed even
if no time zone correction is desired,
calls to gmtime
-like functions
also need to consult a TZif file,
-conventionally named GMT,
+conventionally named Etc/UTC
+(GMT in previous versions),
to see whether leap second corrections are needed.
To convert an application's time_t
timestamps to or from
POSIX time_t
timestamps (for use when, say,
--
2.34.1