tz
Threads by month
- ----- 2026 -----
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2003 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2002 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2001 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2000 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1999 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1998 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1997 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1996 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1995 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1994 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1993 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1992 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1991 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1990 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1989 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1988 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1987 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 1986 -----
- December
- November
August 2014
- 43 participants
- 69 discussions
[PROPOSED PATCH] Make the library thread-safe if THREAD_SAFE is defined.
by Paul Eggert Aug. 25, 2014
by Paul Eggert Aug. 25, 2014
Aug. 25, 2014
* localtime.c [THREAD_SAFE]: Include pthread.h.
(VOLATILE): New macro.
(locallock) [THREAD_SAFE]: New static var.
(lock, unlock): New functions.
(lcl_is_set, gmt_is_set): Now VOLATILE.
(tzsetwall): Move cleaned-up guts to new function tzsetwall_unlocked,
for which this is now merely a locking wrapper.
(tzset): Similarly, for new function tzset_unlocked.
(localtime_tzset): New function, which does proper locking.
(localtime, localtime_r): Use it.
(gmtsub): Do not worry about initializing gmtptr, as that's now
the caller's responsibility.
(gmtime): Reimplement in terms of gmtime_r.
(timegm): Reimplement in terms of timeoff.
(gmtime_r, offtime, mktime, timeoff, time2posix, posix2time):
Lock at start and unlock at end.
* Makefile, NEWS: Document this.
---
Makefile | 3 +
NEWS | 4 +
localtime.c | 249 ++++++++++++++++++++++++++++++++++++++++--------------------
3 files changed, 173 insertions(+), 83 deletions(-)
diff --git a/Makefile b/Makefile
index 5bbd7e7..3d24c2a 100644
--- a/Makefile
+++ b/Makefile
@@ -123,6 +123,9 @@ LDLIBS=
# -DNO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU=1
# if you do not want run time warnings about formats that may cause
# year 2000 grief
+# -DTHREAD_SAFE=1 to make localtime.c thread-safe, as POSIX requires;
+# not needed by the main-program tz code, which is single-threaded.
+# Append other compiler flags as needed, e.g., -pthread on GNU/Linux.
# -Dtime_tz=\"T\" to use T as the time_t type, rather than the system time_t
# -DTZ_DOMAIN=\"foo\" to use "foo" for gettext domain name; default is "tz"
# -DTZ_DOMAINDIR=\"/path\" to use "/path" for gettext directory;
diff --git a/NEWS b/NEWS
index 28974c9..1a78041 100644
--- a/NEWS
+++ b/NEWS
@@ -36,6 +36,10 @@ Unreleased, experimental changes
Changes affecting code
+ The tz library is now thread-safe if compiled with THREAD_SAFE defined.
+ Although not needed for tz's own applications, which are single-threaded,
+ this supports POSIX better if the tz library is used in multithreaded apps.
+
tzselect -c now uses a hybrid distance measure that works better
in Africa. (Thanks to Alan Barrett for noting the problem.)
diff --git a/localtime.c b/localtime.c
index 551b5a2..f499583 100644
--- a/localtime.c
+++ b/localtime.c
@@ -16,6 +16,18 @@
#include "tzfile.h"
#include "fcntl.h"
+#if THREAD_SAFE
+# include <pthread.h>
+# define VOLATILE volatile
+static pthread_mutex_t locallock = PTHREAD_MUTEX_INITIALIZER;
+static int lock(void) { return pthread_mutex_lock(&locallock); }
+static void unlock(void) { pthread_mutex_unlock(&locallock); }
+#else
+# define VOLATILE
+static int lock(void) { return 0; }
+static void unlock(void) { }
+#endif
+
#ifndef TZ_ABBR_MAX_LEN
#define TZ_ABBR_MAX_LEN 16
#endif /* !defined TZ_ABBR_MAX_LEN */
@@ -154,8 +166,8 @@ static struct state gmtmem;
#endif /* !defined TZ_STRLEN_MAX */
static char lcl_TZname[TZ_STRLEN_MAX + 1];
-static int lcl_is_set;
-static int gmt_is_set;
+static int VOLATILE lcl_is_set;
+static int VOLATILE gmt_is_set;
char * tzname[2] = {
(char *) wildabbr,
@@ -1139,6 +1151,21 @@ gmtload(struct state *const sp)
(void) tzparse(gmt, sp, TRUE);
}
+static void
+tzsetwall_unlocked(void)
+{
+ if (lcl_is_set < 0)
+ return;
+#ifdef ALL_STATE
+ if (! lclptr)
+ lclptr = malloc(sizeof *lclptr);
+#endif
+ if (lclptr && tzload(NULL, lclptr, TRUE) != 0)
+ gmtload(lclptr);
+ settzname();
+ lcl_is_set = -1;
+}
+
#ifndef STD_INSPIRED
/*
** A non-static declaration of tzsetwall in a system header file
@@ -1149,65 +1176,71 @@ static
void
tzsetwall(void)
{
- if (lcl_is_set < 0)
- return;
- lcl_is_set = -1;
+ if (lock() != 0)
+ return;
+ tzsetwall_unlocked();
+ unlock();
+}
+static void
+tzset_unlocked(void)
+{
+ int shortname;
+ register char const *name = getenv("TZ");
+
+ if (!name) {
+ tzsetwall_unlocked();
+ return;
+ }
+ shortname = strlen(name) < sizeof lcl_TZname;
+ if (0 < lcl_is_set && strcmp(lcl_TZname, name) == 0)
+ return;
+ if (shortname)
+ strcpy(lcl_TZname, name);
#ifdef ALL_STATE
- if (lclptr == NULL) {
- lclptr = malloc(sizeof *lclptr);
- if (lclptr == NULL) {
- settzname(); /* all we can do */
- return;
- }
- }
+ if (! lclptr)
+ lclptr = malloc(sizeof *lclptr);
#endif /* defined ALL_STATE */
- if (tzload(NULL, lclptr, TRUE) != 0)
- gmtload(lclptr);
- settzname();
+ if (lclptr) {
+ if (*name == '\0') {
+ /*
+ ** User wants it fast rather than right.
+ */
+ lclptr->leapcnt = 0; /* so, we're off a little */
+ lclptr->timecnt = 0;
+ lclptr->typecnt = 0;
+ lclptr->ttis[0].tt_isdst = 0;
+ lclptr->ttis[0].tt_gmtoff = 0;
+ lclptr->ttis[0].tt_abbrind = 0;
+ strcpy(lclptr->chars, gmt);
+ } else if (tzload(name, lclptr, TRUE) != 0)
+ if (name[0] == ':' || tzparse(name, lclptr, FALSE) != 0)
+ gmtload(lclptr);
+ }
+ settzname();
+ lcl_is_set = shortname;
}
void
tzset(void)
{
- register const char * name;
-
- name = getenv("TZ");
- if (name == NULL) {
- tzsetwall();
- return;
- }
-
- if (lcl_is_set > 0 && strcmp(lcl_TZname, name) == 0)
- return;
- lcl_is_set = strlen(name) < sizeof lcl_TZname;
- if (lcl_is_set)
- (void) strcpy(lcl_TZname, name);
+ if (lock() != 0)
+ return;
+ tzset_unlocked();
+ unlock();
+}
+static void
+gmtcheck(void)
+{
+ if (gmt_is_set)
+ return;
#ifdef ALL_STATE
- if (lclptr == NULL) {
- lclptr = malloc(sizeof *lclptr);
- if (lclptr == NULL) {
- settzname(); /* all we can do */
- return;
- }
- }
-#endif /* defined ALL_STATE */
- if (*name == '\0') {
- /*
- ** User wants it fast rather than right.
- */
- lclptr->leapcnt = 0; /* so, we're off a little */
- lclptr->timecnt = 0;
- lclptr->typecnt = 0;
- lclptr->ttis[0].tt_isdst = 0;
- lclptr->ttis[0].tt_gmtoff = 0;
- lclptr->ttis[0].tt_abbrind = 0;
- (void) strcpy(lclptr->chars, gmt);
- } else if (tzload(name, lclptr, TRUE) != 0)
- if (name[0] == ':' || tzparse(name, lclptr, FALSE) != 0)
- (void) gmtload(lclptr);
- settzname();
+ gmtptr = malloc(sizeof *gmtptr);
+#endif
+ if (gmtptr)
+ gmtload(gmtptr);
+ gmt_is_set = TRUE;
}
/*
@@ -1296,11 +1329,25 @@ localsub(const time_t *const timep, const int_fast32_t offset,
return result;
}
+static struct tm *
+localtime_tzset(time_t const *timep, struct tm *tmp, int skip_tzset)
+{
+ int err = lock();
+ if (err) {
+ errno = err;
+ return NULL;
+ }
+ if (!skip_tzset)
+ tzset_unlocked();
+ tmp = localsub(timep, 0, tmp);
+ unlock();
+ return tmp;
+}
+
struct tm *
localtime(const time_t *const timep)
{
- tzset();
- return localsub(timep, 0L, &tm);
+ return localtime_tzset(timep, &tm, 0);
}
/*
@@ -1310,7 +1357,7 @@ localtime(const time_t *const timep)
struct tm *
localtime_r(const time_t *const timep, struct tm *tmp)
{
- return localsub(timep, 0L, tmp);
+ return localtime_tzset(timep, tmp, lcl_is_set);
}
/*
@@ -1323,16 +1370,6 @@ gmtsub(const time_t *const timep, const int_fast32_t offset,
{
register struct tm * result;
- if (!gmt_is_set) {
-#ifdef ALL_STATE
- gmtptr = malloc(sizeof *gmtptr);
- gmt_is_set = gmtptr != NULL;
-#else
- gmt_is_set = TRUE;
-#endif /* defined ALL_STATE */
- if (gmt_is_set)
- gmtload(gmtptr);
- }
result = timesub(timep, offset, gmtptr, tmp);
#ifdef TM_ZONE
/*
@@ -1348,7 +1385,7 @@ gmtsub(const time_t *const timep, const int_fast32_t offset,
struct tm *
gmtime(const time_t *const timep)
{
- return gmtsub(timep, 0L, &tm);
+ return gmtime_r(timep, &tm);
}
/*
@@ -1358,7 +1395,15 @@ gmtime(const time_t *const timep)
struct tm *
gmtime_r(const time_t *const timep, struct tm *tmp)
{
- return gmtsub(timep, 0L, tmp);
+ int err = lock();
+ if (err) {
+ errno = err;
+ return NULL;
+ }
+ gmtcheck();
+ tmp = gmtsub(timep, 0, tmp);
+ unlock();
+ return tmp;
}
#ifdef STD_INSPIRED
@@ -1366,7 +1411,16 @@ gmtime_r(const time_t *const timep, struct tm *tmp)
struct tm *
offtime(const time_t *const timep, const long offset)
{
- return gmtsub(timep, offset, &tm);
+ struct tm *tmp;
+ int err = lock();
+ if (err) {
+ errno = err;
+ return NULL;
+ }
+ gmtcheck();
+ tmp = gmtsub(timep, offset, &tm);
+ unlock();
+ return tmp;
}
#endif /* defined STD_INSPIRED */
@@ -1901,8 +1955,16 @@ time1(struct tm *const tmp,
time_t
mktime(struct tm *const tmp)
{
- tzset();
- return time1(tmp, localsub, 0L);
+ time_t t;
+ int err = lock();
+ if (err) {
+ errno = err;
+ return -1;
+ }
+ tzset_unlocked();
+ t = time1(tmp, localsub, 0);
+ unlock();
+ return t;
}
#ifdef STD_INSPIRED
@@ -1918,17 +1980,25 @@ timelocal(struct tm *const tmp)
time_t
timegm(struct tm *const tmp)
{
- if (tmp != NULL)
- tmp->tm_isdst = 0;
- return time1(tmp, gmtsub, 0L);
+ return timeoff(tmp, 0);
}
time_t
timeoff(struct tm *const tmp, const long offset)
{
- if (tmp != NULL)
- tmp->tm_isdst = 0;
- return time1(tmp, gmtsub, offset);
+ time_t t;
+ int err;
+ if (tmp)
+ tmp->tm_isdst = 0;
+ err = lock();
+ if (err) {
+ errno = err;
+ return -1;
+ }
+ gmtcheck();
+ t = time1(tmp, gmtsub, offset);
+ unlock();
+ return t;
}
#endif /* defined STD_INSPIRED */
@@ -1986,8 +2056,17 @@ leapcorr(time_t *timep)
time_t
time2posix(time_t t)
{
- tzset();
- return t - leapcorr(&t);
+ time_t p;
+ int err = lock();
+ if (err) {
+ errno = err;
+ return -1;
+ }
+ if (!lcl_is_set)
+ tzset_unlocked();
+ p = t - leapcorr(&t);
+ unlock();
+ return p;
}
time_t
@@ -1995,8 +2074,13 @@ posix2time(time_t t)
{
time_t x;
time_t y;
-
- tzset();
+ int err = lock();
+ if (err) {
+ errno = err;
+ return -1;
+ }
+ if (!lcl_is_set)
+ tzset_unlocked();
/*
** For a positive leap second hit, the result
** is not unique. For a negative leap second
@@ -2010,16 +2094,15 @@ posix2time(time_t t)
x++;
y = x - leapcorr(&x);
} while (y < t);
- if (t != y)
- return x - 1;
+ x -= y != t;
} else if (y > t) {
do {
--x;
y = x - leapcorr(&x);
} while (y > t);
- if (t != y)
- return x + 1;
+ x += y != t;
}
+ unlock();
return x;
}
--
1.9.1
2
6
[PROPOSED PATCH 1/4] Fix unlikely buffer overrun when setting date across network.
by Paul Eggert Aug. 23, 2014
by Paul Eggert Aug. 23, 2014
Aug. 23, 2014
* date.c (netsettime) [TSP_SETDATE]: Don't assume gethostname
returns a null-terminated string.
---
date.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/date.c b/date.c
index c8fab75..3b44c94 100644
--- a/date.c
+++ b/date.c
@@ -819,7 +819,6 @@ netsettime(struct timeval ntv)
{
int s, length, port, timed_ack, found, err, waittime;
fd_set ready;
- char hostname[MAXHOSTNAMELEN];
struct timeval tout;
struct servent *sp;
struct tsp msg;
@@ -858,11 +857,15 @@ netsettime(struct timeval ntv)
}
msg.tsp_type = TSP_SETDATE;
msg.tsp_vers = TSPVERSION;
- if (gethostname(hostname, sizeof (hostname))) {
+ msg.tsp_name[sizeof msg.tsp_name - 1] = '\0';
+ if (gethostname(msg.tsp_name, sizeof msg.tsp_name) != 0) {
perror("gethostname");
goto bad;
}
- strncpy(msg.tsp_name, hostname, sizeof (hostname));
+ if (msg.tsp_name[sizeof msg.tsp_name - 1]) {
+ fprintf(stderr, "hostname too long\n");
+ goto bad;
+ }
msg.tsp_seq = htons(0);
msg.tsp_time.tv_sec = htonl(ntv.tv_sec);
msg.tsp_time.tv_usec = htonl(ntv.tv_usec);
--
1.9.1
1
5
[PATCH] * asia (Asia/Kolkata): Add comment about 19th-century Madras time.
by Paul Eggert Aug. 23, 2014
by Paul Eggert Aug. 23, 2014
Aug. 23, 2014
---
asia | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/asia b/asia
index b3afc5d..00e0df3 100644
--- a/asia
+++ b/asia
@@ -880,6 +880,14 @@ Zone Asia/Dili 8:22:20 - LMT 1912 Jan 1
# India
+# From Paul Eggert (2014-08-21):
+# In tomorrow's The Hindu, Nitya Menon reports that India had two civil time
+# zones starting in 1884, one in Bombay and one in Calcutta, and that railways
+# used a third time zone based on Madras time (80 deg. 18'30" E). Also,
+# in 1881 Bombay briefly switched to Madras Time, but switched back. See:
+# http://www.thehindu.com/news/cities/chennai/madras-375-when-madras-clocked-…
+# Ignore this as it predates our 1970 cutoff.
+
# From Paul Eggert (2014-08-11), after a heads-up from Stephen Colebourne:
# According to a Portuguese decree (1911-05-26)
# http://dre.pt/pdf1sdip/1911/05/12500/23132313.pdf
--
1.9.1
2
4
Aug. 23, 2014
* private.h, zdump.c (_GNU_SOURCE): New macro.
* private.h (TM_GMTOFF) [!NO_TM_GMTOFF]:
(TM_ZONE) [!NO_TM_ZONE]: Guess definition if not already defined.
* Makefile, NEWS: Document the above.
---
Makefile | 23 +++++------------------
NEWS | 4 ++++
private.h | 16 ++++++++++++++++
zdump.c | 3 +++
4 files changed, 28 insertions(+), 18 deletions(-)
diff --git a/Makefile b/Makefile
index 4703cba..fa110e2 100644
--- a/Makefile
+++ b/Makefile
@@ -161,25 +161,12 @@ GCC_DEBUG_FLAGS = -Dlint -g3 -O3 -fno-common -fstrict-aliasing \
# (or if you decide to add such a field in your system's "time.h" file),
# add the name to a define such as
# -DTM_GMTOFF=tm_gmtoff
-# or
-# -DTM_GMTOFF=_tm_gmtoff
-# to the end of the "CFLAGS=" line.
-# Neither tm_gmtoff nor _tm_gmtoff is described in X3J11's work;
-# in its work, use of "tm_gmtoff" is described as non-conforming.
-# Both Linux and BSD have done the equivalent of defining TM_GMTOFF in
-# their recent releases.
-#
-# If your system has a "zone abbreviation" field in its "struct tm"s
-# (or if you decide to add such a field in your system's "time.h" file),
-# add the name to a define such as
+# to the end of the "CFLAGS=" line. If not defined, the code attempts to
+# guess TM_GMTOFF from other macros; define NO_TM_GMTOFF to suppress this.
+# Similarly, if your system has a "zone abbreviation" field, define
# -DTM_ZONE=tm_zone
-# or
-# -DTM_ZONE=_tm_zone
-# to the end of the "CFLAGS=" line.
-# Neither tm_zone nor _tm_zone is described in X3J11's work;
-# in its work, use of "tm_zone" is described as non-conforming.
-# Both UCB and Sun have done the equivalent of defining TM_ZONE in
-# their recent releases.
+# and define NO_TM_ZONE to suppress any guessing. These two fields are not
+# required by POSIX, but are widely available on GNU/Linux and BSD dystems.
#
# If you want functions that were inspired by early versions of X3J11's work,
# add
diff --git a/NEWS b/NEWS
index 335a7cf..7bc8b05 100644
--- a/NEWS
+++ b/NEWS
@@ -51,6 +51,10 @@ Unreleased, experimental changes
Although not needed for tz's own applications, which are single-threaded,
this supports POSIX better if the tz library is used in multithreaded apps.
+ The tz code now attempts to infer TM_GMTOFF and TM_ZONE if not
+ already defined, to make it easier to configure on common platforms.
+ Define NO_TM_GMTOFF and NO_TM_ZONE to suppress this.
+
tzselect -c now uses a hybrid distance measure that works better
in Africa. (Thanks to Alan Barrett for noting the problem.)
diff --git a/private.h b/private.h
index 9482790..2389e37 100644
--- a/private.h
+++ b/private.h
@@ -71,6 +71,9 @@
#define ctime_r _incompatible_ctime_r
#endif /* HAVE_INCOMPATIBLE_CTIME_R */
+/* Enable tm_gmtoff and tm_zone on GNUish systems. */
+#define _GNU_SOURCE 1
+
/*
** Nested includes
*/
@@ -337,6 +340,19 @@ time_t posix2time(time_t);
# endif
#endif
+/* Infer TM_ZONE on systems where this information is known, but suppress
+ guessing if NO_TM_ZONE is defined. Similarly for TM_GMTOFF. */
+#if (defined __GLIBC__ \
+ || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ \
+ || (defined __APPLE__ && defined __MACH__))
+# if !defined TM_GMTOFF && !defined NO_TM_GMTOFF
+# define TM_GMTOFF tm_gmtoff
+# endif
+# if !defined TM_ZONE && !defined NO_TM_ZONE
+# define TM_ZONE tm_zone
+# endif
+#endif
+
/*
** Private function declarations.
*/
diff --git a/zdump.c b/zdump.c
index e9a42fd..070ad3c 100644
--- a/zdump.c
+++ b/zdump.c
@@ -18,6 +18,9 @@
# include "private.h"
#endif
+/* Enable tm_gmtoff and tm_zone on GNUish systems. */
+#define _GNU_SOURCE 1
+
#include "stdio.h" /* for stdout, stderr, perror */
#include "string.h" /* for strcpy */
#include "sys/types.h" /* for time_t */
--
1.9.1
2
3
* NEWS: Document this.
---
Makefile | 2 +-
NEWS | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 99d2826..09f614c 100644
--- a/Makefile
+++ b/Makefile
@@ -305,7 +305,7 @@ AR= ar
RANLIB= :
TZCOBJS= zic.o scheck.o ialloc.o
-TZDOBJS= zdump.o localtime.o ialloc.o asctime.o
+TZDOBJS= zdump.o localtime.o asctime.o
DATEOBJS= date.o localtime.o strftime.o asctime.o
LIBSRCS= localtime.c asctime.c difftime.c
LIBOBJS= localtime.o asctime.o difftime.o
diff --git a/NEWS b/NEWS
index 7f15887..66891df 100644
--- a/NEWS
+++ b/NEWS
@@ -71,6 +71,10 @@ Unreleased, experimental changes
The long-obsolete 'gtime' function has been removed.
+ Changes affecting build procedure
+
+ 'zdump' no longer links in ialloc.o, as it's not needed.
+
Changes affecting distribution tarballs
The files checktab.awk and zoneinfo2tdf.pl are now distributed in
--
1.9.1
1
0
Aug. 23, 2014
* NEWS, newctime.3, newstrftime.3, newtzset.3, time2posix.3:
Mention localtime_r etc. Also, use function prototypes rather
than K&R style, and use 'restrict' where POSIX does.
---
NEWS | 3 +++
newctime.3 | 62 ++++++++++++++++++++++++++++++++++++++---------------------
newstrftime.3 | 8 ++------
newtzset.3 | 4 +++-
time2posix.3 | 7 ++-----
5 files changed, 50 insertions(+), 34 deletions(-)
diff --git a/NEWS b/NEWS
index 7bc8b05..0d31a1f 100644
--- a/NEWS
+++ b/NEWS
@@ -85,6 +85,9 @@ Unreleased, experimental changes
A new file CONTRIBUTING is distributed. (Thanks to Tim Parenti for
suggesting a CONTRIBUTING file, and to Walter Harms for debugging it.)
+ The man pages have been updated to use function prototypes, and
+ to document thread-safe variants like localtime_r.
+
The fields in Link lines have been renamed to be more descriptive
and more like the parameters of 'ln'. LINK-FROM has become TARGET,
and LINK-TO has become LINK-NAME.
diff --git a/newctime.3 b/newctime.3
index e9090d5..accefa5 100644
--- a/newctime.3
+++ b/newctime.3
@@ -5,32 +5,32 @@ asctime, ctime, difftime, gmtime, localtime, mktime \- convert date and time
.nf
.ie \n(.g .ds - \f(CW-\fP
.el ds - \-
+.B #include <time.h>
+.PP
.B extern char *tzname[2];
.PP
-.B void tzset()
+.B char *ctime(time_t const *clock);
.PP
-.B #include <sys/types.h>
+.B char *ctime_r(time_t const *clock, char *buf);
.PP
-.B char *ctime(clock)
-.B const time_t *clock;
+.B double difftime(time_t time1, time_t time0);
.PP
-.B double difftime(time1, time0)
-.B time_t time1;
-.B time_t time0;
+.B char *asctime(struct tm const *tm);
.PP
-.B #include <time.h>
+.B "char *asctime_r(struct tm const *restrict tm,"
+.B " char *restrict result);"
.PP
-.B char *asctime(tm)
-.B const struct tm *tm;
+.B struct tm *localtime(time_t const *clock);
.PP
-.B struct tm *localtime(clock)
-.B const time_t *clock;
+.B "struct tm *localtime_r(time_t const *restrict clock,"
+.B " struct tm *restrict result);"
.PP
-.B struct tm *gmtime(clock)
-.B const time_t *clock;
+.B struct tm *gmtime(time_t const *clock);
.PP
-.B time_t mktime(tm)
-.B struct tm *tm;
+.B "struct tm *gmtime_r(time_t const *restrict clock,"
+.B " struct tm *restrict result);"
+.PP
+.B time_t mktime(struct tm *tm);
.PP
.B cc ... \*-ltz
.fi
@@ -110,6 +110,14 @@ structure to a string,
as shown in the above example,
and returns a pointer to the string.
.PP
+.IR Ctime_r ,
+.IR localtime_r ,
+.IR gmtime_r ,
+and
+.I asctime_r
+are like their unsuffixed counterparts, except that they accept an
+additional argument specifying where to store the result if successful.
+.PP
.I Mktime
converts the broken-down time,
expressed as local time,
@@ -234,25 +242,35 @@ newtzset(3),
time(2),
tzfile(5)
.SH NOTES
-The return values point to static data
+The return values of
+.IR asctime ,
+.IR ctime ,
+.IR gmtime ,
+and
+.I localtime
+point to static data
overwritten by each call.
The
.B tm_zone
field of a returned
.B "struct tm"
points to a static array of characters, which
-will also be overwritten at the next call
-(and by calls to
-.IR tzset ).
+can be overwritten by later calls to
+.IR tzset .
+The remaining functions and data are thread-safe.
.PP
-.I Asctime
+.IR Asctime ,
+.IR asctime_r ,
+.IR ctime ,
and
-.I ctime
+.I ctime_r
behave strangely for years before 1000 or after 9999.
The 1989 and 1999 editions of the C Standard say
that years from \-99 through 999 are converted without
extra spaces, but this conflicts with longstanding
tradition and with this implementation.
+The 2011 edition says that the behavior
+is undefined if the year is before 1000 or after 9999.
Traditional implementations of these two functions are
restricted to years in the range 1900 through 2099.
To avoid this portability mess, new programs should use
diff --git a/newstrftime.3 b/newstrftime.3
index 7dd125c..6afc948 100644
--- a/newstrftime.3
+++ b/newstrftime.3
@@ -44,14 +44,10 @@ strftime \- format date and time
.nf
.ie \n(.g .ds - \f(CW-\fP
.el ds - \-
-.B #include <sys/types.h>
.B #include <time.h>
.PP
-.B size_t strftime(buf, maxsize, format, timeptr)
-.B char *buf;
-.B size_t maxsize;
-.B const char *format;
-.B const struct tm *timeptr
+.B "size_t strftime(char *restrict buf, size_t maxsize,"
+.B " char const *restrict format, struct tm const *restrict timeptr);"
.PP
.B cc ... \-ltz
.fi
diff --git a/newtzset.3 b/newtzset.3
index 46410bb..51c4197 100644
--- a/newtzset.3
+++ b/newtzset.3
@@ -5,7 +5,9 @@ tzset \- initialize time conversion information
.nf
.ie \n(.g .ds - \f(CW-\fP
.el ds - \-
-.B void tzset()
+.B #include <time.h>
+.PP
+.B void tzset(void);
.PP
.B cc ... \*-ltz
.fi
diff --git a/time2posix.3 b/time2posix.3
index 75d8097..e4b8e81 100644
--- a/time2posix.3
+++ b/time2posix.3
@@ -5,14 +5,11 @@ time2posix, posix2time \- convert seconds since the Epoch
.nf
.ie \n(.g .ds - \f(CW-\fP
.el ds - \-
-.B #include <sys/types.h>
.B #include <time.h>
.PP
-.B time_t time2posix(t)
-.B time_t t
+.B time_t time2posix(time_t t);
.PP
-.B time_t posix2time(t)
-.B time_t t
+.B time_t posix2time(time_t t);
.PP
.B cc ... \*-ltz
.fi
--
1.9.1
1
3
[PROPOSED PATCH] * asia (Asia/Kolkata): Add comment about 19th-century Madras time.
by Paul Eggert Aug. 22, 2014
by Paul Eggert Aug. 22, 2014
Aug. 22, 2014
---
asia | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/asia b/asia
index b3afc5d..00e0df3 100644
--- a/asia
+++ b/asia
@@ -880,6 +880,14 @@ Zone Asia/Dili 8:22:20 - LMT 1912 Jan 1
# India
+# From Paul Eggert (2014-08-21):
+# In tomorrow's The Hindu, Nitya Menon reports that India had two civil time
+# zones starting in 1884, one in Bombay and one in Calcutta, and that railways
+# used a third time zone based on Madras time (80 deg. 18'30" E). Also,
+# in 1881 Bombay briefly switched to Madras Time, but switched back. See:
+# http://www.thehindu.com/news/cities/chennai/madras-375-when-madras-clocked-…
+# Ignore this as it predates our 1970 cutoff.
+
# From Paul Eggert (2014-08-11), after a heads-up from Stephen Colebourne:
# According to a Portuguese decree (1911-05-26)
# http://dre.pt/pdf1sdip/1911/05/12500/23132313.pdf
--
1.9.1
1
0
Although the cast to void in usage like '(void) printf ("Hello")'
may have been helpful decades ago when Lint Was Your Friend,
nowadays such casts are not helpful. The tz code is currently not
consistent about this: sometimes the casts are present, and
sometimes absent. As they make the code harder to read, let's
remove them.
* asctime.c, date.c, ialloc.c, localtime.c, strftime.c, zdump.c, zic.c:
Don't cast calls to 'void'.
---
asctime.c | 4 +-
date.c | 68 +++++++++++++++----------------
ialloc.c | 2 +-
localtime.c | 6 +--
strftime.c | 30 +++++++-------
zdump.c | 90 ++++++++++++++++++++---------------------
zic.c | 130 ++++++++++++++++++++++++++++++------------------------------
7 files changed, 165 insertions(+), 165 deletions(-)
diff --git a/asctime.c b/asctime.c
index e057711..0ce1209 100644
--- a/asctime.c
+++ b/asctime.c
@@ -99,11 +99,11 @@ asctime_r(register const struct tm *timeptr, char *buf)
** Assume that strftime is unaffected by other out-of-range members
** (e.g., timeptr->tm_mday) when processing "%Y".
*/
- (void) strftime(year, sizeof year, "%Y", timeptr);
+ strftime(year, sizeof year, "%Y", timeptr);
/*
** We avoid using snprintf since it's not available on all systems.
*/
- (void) sprintf(result,
+ sprintf(result,
((strlen(year) <= 4) ? ASCTIME_FMT : ASCTIME_FMT_B),
wn, mn,
timeptr->tm_mday, timeptr->tm_hour,
diff --git a/date.c b/date.c
index de56652..c2a39f2 100644
--- a/date.c
+++ b/date.c
@@ -91,13 +91,13 @@ main(const int argc, char *argv[])
INITIALIZE(dousg);
#ifdef LC_ALL
- (void) setlocale(LC_ALL, "");
+ setlocale(LC_ALL, "");
#endif /* defined(LC_ALL) */
#if HAVE_GETTEXT
#ifdef TZ_DOMAINDIR
- (void) bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR);
+ bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR);
#endif /* defined(TEXTDOMAINDIR) */
- (void) textdomain(TZ_DOMAIN);
+ textdomain(TZ_DOMAIN);
#endif /* HAVE_GETTEXT */
t = now = time(NULL);
format = value = NULL;
@@ -111,7 +111,7 @@ main(const int argc, char *argv[])
break;
case 'r': /* seconds since 1970 */
if (rflag) {
- (void) fprintf(stderr,
+ fprintf(stderr,
_("date: error: multiple -r's used"));
usage();
}
@@ -134,7 +134,7 @@ main(const int argc, char *argv[])
break;
case 'd': /* daylight saving time */
if (dflag) {
- (void) fprintf(stderr,
+ fprintf(stderr,
_("date: error: multiple -d's used"));
usage();
}
@@ -147,7 +147,7 @@ main(const int argc, char *argv[])
break;
case 't': /* minutes west of UTC */
if (tflag) {
- (void) fprintf(stderr,
+ fprintf(stderr,
_("date: error: multiple -t's used"));
usage();
}
@@ -162,7 +162,7 @@ main(const int argc, char *argv[])
break;
case 'a': /* adjustment */
if (aflag) {
- (void) fprintf(stderr,
+ fprintf(stderr,
_("date: error: multiple -a's used"));
usage();
}
@@ -189,14 +189,14 @@ main(const int argc, char *argv[])
if (format == NULL)
format = cp + 1;
else {
- (void) fprintf(stderr,
+ fprintf(stderr,
_("date: error: multiple formats in command line\n"));
usage();
}
else if (value == NULL && !rflag)
value = cp;
else {
- (void) fprintf(stderr,
+ fprintf(stderr,
_("date: error: multiple values in command line\n"));
usage();
}
@@ -277,7 +277,7 @@ _("date: error: multiple values in command line\n"));
#if HAVE_SETTIMEOFDAY != 2
(void) dsttime;
(void) minuteswest;
- (void) fprintf(stderr,
+ fprintf(stderr,
_("date: warning: kernel doesn't keep -d/-t information, option ignored\n"));
#endif /* HAVE_SETTIMEOFDAY != 2 */
}
@@ -307,7 +307,7 @@ dogmt(void)
continue;
fakeenv = malloc((n + 2) * sizeof *fakeenv);
if (fakeenv == NULL) {
- (void) perror(_("Memory exhausted"));
+ perror(_("Memory exhausted"));
errensure();
exit(retval);
}
@@ -352,15 +352,15 @@ reset(const time_t newt, const int nflag)
/*
** Wouldn't it be great if stime returned the old time?
*/
- (void) time(&oldt);
+ oldt = time(NULL);
if (stime(&newt) != 0)
oops("stime");
s.before.ut_type = OLD_TIME;
s.before.ut_time = oldt;
- (void) strcpy(s.before.ut_line, OTIME_MSG);
+ strcpy(s.before.ut_line, OTIME_MSG);
s.after.ut_type = NEW_TIME;
s.after.ut_time = newt;
- (void) strcpy(s.after.ut_line, NTIME_MSG);
+ strcpy(s.after.ut_line, NTIME_MSG);
fid = open(WTMP_FILE, O_WRONLY | O_APPEND);
if (fid < 0)
oops(_("log file open"));
@@ -375,10 +375,10 @@ reset(const time_t newt, const int nflag)
#if HAVE_UTMPX_H
sx.before.ut_type = OLD_TIME;
sx.before.ut_tv.tv_sec = oldt;
- (void) strcpy(sx.before.ut_line, OTIME_MSG);
+ strcpy(sx.before.ut_line, OTIME_MSG);
sx.after.ut_type = NEW_TIME;
sx.after.ut_tv.tv_sec = newt;
- (void) strcpy(sx.after.ut_line, NTIME_MSG);
+ strcpy(sx.after.ut_line, NTIME_MSG);
#if defined WTMPX_FILE && !SUPPRESS_WTMPX_FILE_UPDATE
/* In Solaris 2.5 (and presumably other systems),
'date' does not update /var/adm/wtmpx.
@@ -471,7 +471,7 @@ static void
wildinput(const char *const item, const char *const value,
const char *const reason)
{
- (void) fprintf(stderr,
+ fprintf(stderr,
_("date: error: bad command line %s \"%s\", %s\n"),
item, value, reason);
usage();
@@ -495,7 +495,7 @@ nondigit(register const char *cp)
static void
usage(void)
{
- (void) fprintf(stderr,
+ fprintf(stderr,
_("date: usage: date [-u] [-c] [-r seconds] [-n]"
" [-d dst] [-t min-west] [-a sss.fff]"
" [[yyyy]mmddhhmm[yyyy][.ss]] [+format]\n"));
@@ -508,9 +508,9 @@ oops(const char *const string)
{
int e = errno;
- (void) fprintf(stderr, _("date: error: "));
+ fprintf(stderr, _("date: error: "));
errno = e;
- (void) perror(string);
+ perror(string);
errensure();
display(NULL, time(NULL));
exit(retval);
@@ -523,17 +523,17 @@ display(const char *const format, time_t const now)
tmp = localtime(&now);
if (!tmp) {
- (void) fprintf(stderr,
+ fprintf(stderr,
_("date: error: time out of range\n"));
errensure();
return;
}
timeout(stdout, format ? format : "%+", tmp);
- (void) putchar('\n');
- (void) fflush(stdout);
- (void) fflush(stderr);
+ putchar('\n');
+ fflush(stdout);
+ fflush(stderr);
if (ferror(stdout) || ferror(stderr)) {
- (void) fprintf(stderr,
+ fprintf(stderr,
_("date: error: couldn't write results\n"));
errensure();
}
@@ -552,7 +552,7 @@ timeout(FILE *const fp, const char *const format, const struct tm *tmp)
if (*format == '\0')
return;
if (!tmp) {
- (void) fprintf(stderr, _("date: error: time out of range\n"));
+ fprintf(stderr, _("date: error: time out of range\n"));
errensure();
return;
}
@@ -562,7 +562,7 @@ timeout(FILE *const fp, const char *const format, const struct tm *tmp)
cp = malloc(size);
for ( ; ; ) {
if (cp == NULL) {
- (void) fprintf(stderr,
+ fprintf(stderr,
_("date: error: can't get memory\n"));
errensure();
exit(retval);
@@ -574,7 +574,7 @@ timeout(FILE *const fp, const char *const format, const struct tm *tmp)
size += INCR;
cp = realloc(cp, size);
}
- (void) fwrite(cp, 1, result, fp);
+ fwrite(cp, 1, result, fp);
free(cp);
}
@@ -778,7 +778,7 @@ iffy(const time_t thist, const time_t thatt,
struct tm *tmp;
int dst;
- (void) fprintf(stderr, _("date: warning: ambiguous time \"%s\", %s.\n"),
+ fprintf(stderr, _("date: warning: ambiguous time \"%s\", %s.\n"),
value, reason);
tmp = gmtime(&thist);
/*
@@ -790,7 +790,7 @@ iffy(const time_t thist, const time_t thatt,
tmp = localtime(&thist);
dst = tmp ? tmp->tm_isdst : 0;
timeout(stderr, _("to get %c"), tmp);
- (void) fprintf(stderr, _(" (%s). Use\n"),
+ fprintf(stderr, _(" (%s). Use\n"),
dst ? _("summer time") : _("standard time"));
tmp = gmtime(&thatt);
timeout(stderr, _("\tdate -u %m%d%H\
@@ -799,7 +799,7 @@ iffy(const time_t thist, const time_t thatt,
tmp = localtime(&thatt);
dst = tmp ? tmp->tm_isdst : 0;
timeout(stderr, _("to get %c"), tmp);
- (void) fprintf(stderr, _(" (%s).\n"),
+ fprintf(stderr, _(" (%s).\n"),
dst ? _("summer time") : _("standard time"));
errensure();
exit(retval);
@@ -865,7 +865,7 @@ netsettime(struct timeval ntv)
perror("gethostname");
goto bad;
}
- (void) strncpy(msg.tsp_name, hostname, sizeof (hostname));
+ strncpy(msg.tsp_name, hostname, sizeof (hostname));
msg.tsp_seq = htons(0);
msg.tsp_time.tv_sec = htonl(ntv.tv_sec);
msg.tsp_time.tv_usec = htonl(ntv.tv_usec);
@@ -914,7 +914,7 @@ loop:
goto loop;
case TSP_DATEACK:
- (void)close(s);
+ lose(s);
return (1);
default:
@@ -929,7 +929,7 @@ loop:
fputs(_("date: Can't reach time daemon, time set locally.\n"),
stderr);
bad:
- (void)close(s);
+ lose(s);
retval = 2;
return (0);
}
diff --git a/ialloc.c b/ialloc.c
index b6f0188..e228db5 100644
--- a/ialloc.c
+++ b/ialloc.c
@@ -21,7 +21,7 @@ icatalloc(char *const old, const char *const new)
else oldsize = strlen(old);
if ((result = realloc(old, oldsize + newsize + 1)) != NULL)
if (new != NULL)
- (void) strcpy(result + oldsize, new);
+ strcpy(result + oldsize, new);
return result;
}
diff --git a/localtime.c b/localtime.c
index fef273d..8a66650 100644
--- a/localtime.c
+++ b/localtime.c
@@ -1134,11 +1134,11 @@ tzparse(const char *name, register struct state *const sp,
if ((size_t) sp->charcnt > sizeof sp->chars)
return -1;
cp = sp->chars;
- (void) strncpy(cp, stdname, stdlen);
+ strncpy(cp, stdname, stdlen);
cp += stdlen;
*cp++ = '\0';
if (dstlen != 0) {
- (void) strncpy(cp, dstname, dstlen);
+ strncpy(cp, dstname, dstlen);
*(cp + dstlen) = '\0';
}
return 0;
@@ -1148,7 +1148,7 @@ static void
gmtload(struct state *const sp)
{
if (tzload(gmt, sp, TRUE) != 0)
- (void) tzparse(gmt, sp, TRUE);
+ tzparse(gmt, sp, TRUE);
}
static void
diff --git a/strftime.c b/strftime.c
index 9fbb1ec..259c90a 100644
--- a/strftime.c
+++ b/strftime.c
@@ -129,18 +129,18 @@ strftime(char * const s, const size_t maxsize, const char *const format,
p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn);
#ifndef NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU
if (warn != IN_NONE && getenv(YEAR_2000_NAME) != NULL) {
- (void) fprintf(stderr, "\n");
+ fprintf(stderr, "\n");
if (format == NULL)
- (void) fprintf(stderr, "NULL strftime format ");
- else (void) fprintf(stderr, "strftime format \"%s\" ",
+ fprintf(stderr, "NULL strftime format ");
+ else fprintf(stderr, "strftime format \"%s\" ",
format);
- (void) fprintf(stderr, "yields only two digits of years in ");
+ fprintf(stderr, "yields only two digits of years in ");
if (warn == IN_SOME)
- (void) fprintf(stderr, "some locales");
+ fprintf(stderr, "some locales");
else if (warn == IN_THIS)
- (void) fprintf(stderr, "the current locale");
- else (void) fprintf(stderr, "all locales");
- (void) fprintf(stderr, "\n");
+ fprintf(stderr, "the current locale");
+ else fprintf(stderr, "all locales");
+ fprintf(stderr, "\n");
}
#endif /* !defined NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU */
if (p == s + maxsize)
@@ -311,9 +311,9 @@ label:
tm = *t;
mkt = mktime(&tm);
if (TYPE_SIGNED(time_t))
- (void) sprintf(buf, "%"PRIdMAX,
+ sprintf(buf, "%"PRIdMAX,
(intmax_t) mkt);
- else (void) sprintf(buf, "%"PRIuMAX,
+ else sprintf(buf, "%"PRIuMAX,
(uintmax_t) mkt);
pt = _add(buf, pt, ptlim);
}
@@ -564,7 +564,7 @@ _conv(const int n, const char *const format, char *const pt,
{
char buf[INT_STRLEN_MAXIMUM(int) + 1];
- (void) sprintf(buf, format, n);
+ sprintf(buf, format, n);
return _add(buf, pt, ptlim);
}
@@ -660,14 +660,14 @@ _loc(void)
((sizeof locale_home) + namesize + (sizeof lc_time)))
goto no_locale;
oldsun = 0;
- (void) sprintf(filename, "%s/%s/%s", locale_home, name, lc_time);
+ sprintf(filename, "%s/%s/%s", locale_home, name, lc_time);
fd = open(filename, O_RDONLY);
if (fd < 0) {
/*
** Old Sun systems have a different naming and data convention.
*/
oldsun = 1;
- (void) sprintf(filename, "%s/%s/%s", locale_home,
+ sprintf(filename, "%s/%s/%s", locale_home,
lc_time, name);
fd = open(filename, O_RDONLY);
if (fd < 0)
@@ -682,7 +682,7 @@ _loc(void)
lbuf = (lbuf == NULL) ? malloc(bufsize) : realloc(lbuf, bufsize);
if (lbuf == NULL)
goto bad_locale;
- (void) strcpy(lbuf, name);
+ strcpy(lbuf, name);
p = lbuf + namesize;
plim = p + st.st_size;
if (read(fd, p, st.st_size) != st.st_size)
@@ -725,7 +725,7 @@ _loc(void)
bad_lbuf:
free(lbuf);
bad_locale:
- (void) close(fd);
+ close(fd);
no_locale:
localebuf = C_time_locale;
locale_buf = NULL;
diff --git a/zdump.c b/zdump.c
index 515a80f..cdcde5a 100644
--- a/zdump.c
+++ b/zdump.c
@@ -250,20 +250,20 @@ my_localtime(time_t *tp)
tm = *tmp;
t = mktime(&tm);
if (t != *tp) {
- (void) fflush(stdout);
- (void) fprintf(stderr, "\n%s: ", progname);
- (void) fprintf(stderr, tformat(), *tp);
- (void) fprintf(stderr, " ->");
- (void) fprintf(stderr, " year=%d", tmp->tm_year);
- (void) fprintf(stderr, " mon=%d", tmp->tm_mon);
- (void) fprintf(stderr, " mday=%d", tmp->tm_mday);
- (void) fprintf(stderr, " hour=%d", tmp->tm_hour);
- (void) fprintf(stderr, " min=%d", tmp->tm_min);
- (void) fprintf(stderr, " sec=%d", tmp->tm_sec);
- (void) fprintf(stderr, " isdst=%d", tmp->tm_isdst);
- (void) fprintf(stderr, " -> ");
- (void) fprintf(stderr, tformat(), t);
- (void) fprintf(stderr, "\n");
+ fflush(stdout);
+ fprintf(stderr, "\n%s: ", progname);
+ fprintf(stderr, tformat(), *tp);
+ fprintf(stderr, " ->");
+ fprintf(stderr, " year=%d", tmp->tm_year);
+ fprintf(stderr, " mon=%d", tmp->tm_mon);
+ fprintf(stderr, " mday=%d", tmp->tm_mday);
+ fprintf(stderr, " hour=%d", tmp->tm_hour);
+ fprintf(stderr, " min=%d", tmp->tm_min);
+ fprintf(stderr, " sec=%d", tmp->tm_sec);
+ fprintf(stderr, " isdst=%d", tmp->tm_isdst);
+ fprintf(stderr, " -> ");
+ fprintf(stderr, tformat(), t);
+ fprintf(stderr, "\n");
}
}
return tmp;
@@ -298,8 +298,8 @@ abbrok(const char *const abbrp, const char *const zone)
}
if (wp == NULL)
return;
- (void) fflush(stdout);
- (void) fprintf(stderr,
+ fflush(stdout);
+ fprintf(stderr,
_("%s: warning: zone \"%s\" abbreviation \"%s\" %s\n"),
progname, zone, abbrp, wp);
warned = TRUE;
@@ -308,7 +308,7 @@ abbrok(const char *const abbrp, const char *const zone)
static void
usage(FILE * const stream, const int status)
{
- (void) fprintf(stream,
+ fprintf(stream,
_("%s: usage: %s [--version] [--help] [-{vV}] [-{ct} [lo,]hi] zonename ...\n"
"\n"
"Report bugs to %s.\n"),
@@ -338,16 +338,16 @@ main(int argc, char *argv[])
cutlotime = absolute_min_time;
cuthitime = absolute_max_time;
#if HAVE_GETTEXT
- (void) setlocale(LC_ALL, "");
+ setlocale(LC_ALL, "");
#ifdef TZ_DOMAINDIR
- (void) bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR);
+ bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR);
#endif /* defined TEXTDOMAINDIR */
- (void) textdomain(TZ_DOMAIN);
+ textdomain(TZ_DOMAIN);
#endif /* HAVE_GETTEXT */
progname = argv[0];
for (i = 1; i < argc; ++i)
if (strcmp(argv[i], "--version") == 0) {
- (void) printf("zdump %s%s\n", PKGVERSION, TZVERSION);
+ printf("zdump %s%s\n", PKGVERSION, TZVERSION);
exit(EXIT_SUCCESS);
} else if (strcmp(argv[i], "--help") == 0) {
usage(stdout, EXIT_SUCCESS);
@@ -386,7 +386,7 @@ main(int argc, char *argv[])
cutloyear = lo;
cuthiyear = hi;
} else {
-(void) fprintf(stderr, _("%s: wild -c argument %s\n"),
+ fprintf(stderr, _("%s: wild -c argument %s\n"),
progname, cutarg);
exit(EXIT_FAILURE);
}
@@ -418,14 +418,14 @@ main(int argc, char *argv[])
cuthitime = hi;
}
} else {
- (void) fprintf(stderr,
+ fprintf(stderr,
_("%s: wild -t argument %s\n"),
progname, cuttimes);
exit(EXIT_FAILURE);
}
}
}
- (void) time(&now);
+ now = time(NULL);
longest = 0;
for (i = optind; i < argc; ++i)
if (strlen(argv[i]) > longest)
@@ -439,11 +439,11 @@ main(int argc, char *argv[])
fakeenv = malloc((i + 2) * sizeof *fakeenv);
if (fakeenv == NULL
|| (fakeenv[0] = malloc(longest + 4)) == NULL) {
- (void) perror(progname);
- exit(EXIT_FAILURE);
+ perror(progname);
+ exit(EXIT_FAILURE);
}
to = 0;
- (void) strcpy(fakeenv[to++], "TZ=");
+ strcpy(fakeenv[to++], "TZ=");
for (from = 0; environ[from] != NULL; ++from)
if (strncmp(environ[from], "TZ=", 3) != 0)
fakeenv[to++] = environ[from];
@@ -453,7 +453,7 @@ main(int argc, char *argv[])
for (i = optind; i < argc; ++i) {
static char buf[MAX_STRING_LENGTH];
- (void) strcpy(&fakeenv[0][3], argv[i]);
+ strcpy(&fakeenv[0][3], argv[i]);
if (! (vflag | Vflag)) {
show(argv[i], now, FALSE);
continue;
@@ -470,7 +470,7 @@ main(int argc, char *argv[])
tmp = my_localtime(&t);
if (tmp != NULL) {
tm = *tmp;
- (void) strncpy(buf, abbr(&tm), (sizeof buf) - 1);
+ strncpy(buf, abbr(&tm), (sizeof buf) - 1);
}
for ( ; ; ) {
newt = (t < absolute_max_time - SECSPERDAY / 2
@@ -489,7 +489,7 @@ main(int argc, char *argv[])
newtmp = localtime(&newt);
if (newtmp != NULL) {
newtm = *newtmp;
- (void) strncpy(buf,
+ strncpy(buf,
abbr(&newtm),
(sizeof buf) - 1);
}
@@ -507,8 +507,8 @@ main(int argc, char *argv[])
}
}
if (fflush(stdout) || ferror(stdout)) {
- (void) fprintf(stderr, "%s: ", progname);
- (void) perror(_("Error writing to standard output"));
+ fprintf(stderr, "%s: ", progname);
+ perror(_("Error writing to standard output"));
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
@@ -572,7 +572,7 @@ hunt(char *name, time_t lot, time_t hit)
lotmp = my_localtime(&lot);
if (lotmp != NULL) {
lotm = *lotmp;
- (void) strncpy(loab, abbr(&lotm), (sizeof loab) - 1);
+ strncpy(loab, abbr(&lotm), (sizeof loab) - 1);
}
for ( ; ; ) {
time_t diff = hit - lot;
@@ -631,30 +631,30 @@ show(char *zone, time_t t, int v)
{
register struct tm * tmp;
- (void) printf("%-*s ", (int) longest, zone);
+ printf("%-*s ", (int) longest, zone);
if (v) {
tmp = gmtime(&t);
if (tmp == NULL) {
- (void) printf(tformat(), t);
+ printf(tformat(), t);
} else {
dumptime(tmp);
- (void) printf(" UT");
+ printf(" UT");
}
- (void) printf(" = ");
+ printf(" = ");
}
tmp = my_localtime(&t);
dumptime(tmp);
if (tmp != NULL) {
if (*abbr(tmp) != '\0')
- (void) printf(" %s", abbr(tmp));
+ printf(" %s", abbr(tmp));
if (v) {
- (void) printf(" isdst=%d", tmp->tm_isdst);
+ printf(" isdst=%d", tmp->tm_isdst);
#ifdef TM_GMTOFF
- (void) printf(" gmtoff=%ld", tmp->TM_GMTOFF);
+ printf(" gmtoff=%ld", tmp->TM_GMTOFF);
#endif /* defined TM_GMTOFF */
}
}
- (void) printf("\n");
+ printf("\n");
if (tmp != NULL && *abbr(tmp) != '\0')
abbrok(abbr(tmp), zone);
}
@@ -715,7 +715,7 @@ dumptime(register const struct tm *timeptr)
register int trail;
if (timeptr == NULL) {
- (void) printf("NULL");
+ printf("NULL");
return;
}
/*
@@ -731,7 +731,7 @@ dumptime(register const struct tm *timeptr)
(int) (sizeof mon_name / sizeof mon_name[0]))
mn = "???";
else mn = mon_name[timeptr->tm_mon];
- (void) printf("%.3s %.3s%3d %.2d:%.2d:%.2d ",
+ printf("%.3s %.3s%3d %.2d:%.2d:%.2d ",
wn, mn,
timeptr->tm_mday, timeptr->tm_hour,
timeptr->tm_min, timeptr->tm_sec);
@@ -748,6 +748,6 @@ dumptime(register const struct tm *timeptr)
++lead;
}
if (lead == 0)
- (void) printf("%d", trail);
- else (void) printf("%d%d", lead, ((trail < 0) ? -trail : trail));
+ printf("%d", trail);
+ else printf("%d%d", lead, ((trail < 0) ? -trail : trail));
}
diff --git a/zic.c b/zic.c
index a700291..ea63f76 100644
--- a/zic.c
+++ b/zic.c
@@ -426,9 +426,9 @@ verror(const char *const string, va_list args)
fprintf(stderr, _("\"%s\", line %d: "), filename, linenum);
vfprintf(stderr, string, args);
if (rfilename != NULL)
- (void) fprintf(stderr, _(" (rule from \"%s\", line %d)"),
+ fprintf(stderr, _(" (rule from \"%s\", line %d)"),
rfilename, rlinenum);
- (void) fprintf(stderr, "\n");
+ fprintf(stderr, "\n");
++errors;
}
@@ -455,7 +455,7 @@ warning(const char *const string, ...)
static _Noreturn void
usage(FILE *stream, int status)
{
- (void) fprintf(stream, _("%s: usage is %s \
+ fprintf(stream, _("%s: usage is %s \
[ --version ] [ --help ] [ -v ] [ -l localtime ] [ -p posixrules ] \\\n\
\t[ -d directory ] [ -L leapseconds ] [ -y yearistype ] [ filename ... ]\n\
\n\
@@ -478,24 +478,24 @@ main(int argc, char **argv)
register int c;
#ifdef S_IWGRP
- (void) umask(umask(S_IWGRP | S_IWOTH) | (S_IWGRP | S_IWOTH));
+ umask(umask(S_IWGRP | S_IWOTH) | (S_IWGRP | S_IWOTH));
#endif
#if HAVE_GETTEXT
- (void) setlocale(LC_ALL, "");
+ setlocale(LC_ALL, "");
#ifdef TZ_DOMAINDIR
- (void) bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR);
+ bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR);
#endif /* defined TEXTDOMAINDIR */
- (void) textdomain(TZ_DOMAIN);
+ textdomain(TZ_DOMAIN);
#endif /* HAVE_GETTEXT */
progname = argv[0];
if (TYPE_BIT(zic_t) < 64) {
- (void) fprintf(stderr, "%s: %s\n", progname,
+ fprintf(stderr, "%s: %s\n", progname,
_("wild compilation-time specification of zic_t"));
exit(EXIT_FAILURE);
}
for (i = 1; i < argc; ++i)
if (strcmp(argv[i], "--version") == 0) {
- (void) printf("zic %s%s\n", PKGVERSION, TZVERSION);
+ printf("zic %s%s\n", PKGVERSION, TZVERSION);
exit(EXIT_SUCCESS);
} else if (strcmp(argv[i], "--help") == 0) {
usage(stdout, EXIT_SUCCESS);
@@ -508,7 +508,7 @@ main(int argc, char **argv)
if (directory == NULL)
directory = optarg;
else {
- (void) fprintf(stderr,
+ fprintf(stderr,
_("%s: More than one -d option specified\n"),
progname);
exit(EXIT_FAILURE);
@@ -518,7 +518,7 @@ _("%s: More than one -d option specified\n"),
if (lcltime == NULL)
lcltime = optarg;
else {
- (void) fprintf(stderr,
+ fprintf(stderr,
_("%s: More than one -l option specified\n"),
progname);
exit(EXIT_FAILURE);
@@ -528,7 +528,7 @@ _("%s: More than one -l option specified\n"),
if (psxrules == NULL)
psxrules = optarg;
else {
- (void) fprintf(stderr,
+ fprintf(stderr,
_("%s: More than one -p option specified\n"),
progname);
exit(EXIT_FAILURE);
@@ -538,7 +538,7 @@ _("%s: More than one -p option specified\n"),
if (yitcommand == NULL)
yitcommand = optarg;
else {
- (void) fprintf(stderr,
+ fprintf(stderr,
_("%s: More than one -y option specified\n"),
progname);
exit(EXIT_FAILURE);
@@ -548,7 +548,7 @@ _("%s: More than one -y option specified\n"),
if (leapsec == NULL)
leapsec = optarg;
else {
- (void) fprintf(stderr,
+ fprintf(stderr,
_("%s: More than one -L option specified\n"),
progname);
exit(EXIT_FAILURE);
@@ -558,7 +558,7 @@ _("%s: More than one -L option specified\n"),
noise = TRUE;
break;
case 's':
- (void) printf("%s: -s ignored\n", progname);
+ printf("%s: -s ignored\n", progname);
break;
}
if (optind == argc - 1 && strcmp(argv[optind], "=") == 0)
@@ -701,7 +701,7 @@ dolink(const char *const fromfield, const char *const tofield)
exit(EXIT_FAILURE);
}
if (itsdir(toname) <= 0)
- (void) remove(toname);
+ remove(toname);
if (link(fromname, toname) != 0) {
int result;
@@ -738,7 +738,7 @@ warning(_("hard link failed, symbolic link used"));
fp = fopen(fromname, "rb");
if (!fp) {
const char *e = strerror(errno);
- (void) fprintf(stderr,
+ fprintf(stderr,
_("%s: Can't read %s: %s\n"),
progname, fromname, e);
exit(EXIT_FAILURE);
@@ -746,7 +746,7 @@ warning(_("hard link failed, symbolic link used"));
tp = fopen(toname, "wb");
if (!tp) {
const char *e = strerror(errno);
- (void) fprintf(stderr,
+ fprintf(stderr,
_("%s: Can't create %s: %s\n"),
progname, toname, e);
exit(EXIT_FAILURE);
@@ -754,13 +754,13 @@ warning(_("hard link failed, symbolic link used"));
while ((c = getc(fp)) != EOF)
putc(c, tp);
if (ferror(fp) || fclose(fp)) {
- (void) fprintf(stderr,
+ fprintf(stderr,
_("%s: Error reading %s\n"),
progname, fromname);
exit(EXIT_FAILURE);
}
if (ferror(tp) || fclose(tp)) {
- (void) fprintf(stderr,
+ fprintf(stderr,
_("%s: Error writing %s\n"),
progname, toname);
exit(EXIT_FAILURE);
@@ -851,7 +851,7 @@ associate(void)
register int i, j;
if (nrules != 0) {
- (void) qsort(rules, nrules, sizeof *rules, rcomp);
+ qsort(rules, nrules, sizeof *rules, rcomp);
for (i = 0; i < nrules - 1; ++i) {
if (strcmp(rules[i].r_name,
rules[i + 1].r_name) != 0)
@@ -935,7 +935,7 @@ infile(const char *name)
} else if ((fp = fopen(name, "r")) == NULL) {
const char *e = strerror(errno);
- (void) fprintf(stderr, _("%s: Can't open %s: %s\n"),
+ fprintf(stderr, _("%s: Can't open %s: %s\n"),
progname, name, e);
exit(EXIT_FAILURE);
}
@@ -981,14 +981,14 @@ infile(const char *name)
break;
case LC_LEAP:
if (name != leapsec)
- (void) fprintf(stderr,
+ fprintf(stderr,
_("%s: Leap line in non leap seconds file %s\n"),
progname, name);
else inleap(fields, nfields);
wantcont = FALSE;
break;
default: /* "cannot happen" */
- (void) fprintf(stderr,
+ fprintf(stderr,
_("%s: panic: Invalid l_value %d\n"),
progname, lp->l_value);
exit(EXIT_FAILURE);
@@ -997,14 +997,14 @@ _("%s: panic: Invalid l_value %d\n"),
free(fields);
}
if (ferror(fp)) {
- (void) fprintf(stderr, _("%s: Error reading %s\n"),
+ fprintf(stderr, _("%s: Error reading %s\n"),
progname, filename);
exit(EXIT_FAILURE);
}
if (fp != stdin && fclose(fp)) {
const char *e = strerror(errno);
- (void) fprintf(stderr, _("%s: Error closing %s: %s\n"),
+ fprintf(stderr, _("%s: Error closing %s: %s\n"),
progname, filename, e);
exit(EXIT_FAILURE);
}
@@ -1396,7 +1396,7 @@ rulesub(register struct rule *const rp,
rp->r_loyear = ZIC_MAX;
break;
default: /* "cannot happen" */
- (void) fprintf(stderr,
+ fprintf(stderr,
_("%s: panic: Invalid l_value %d\n"),
progname, lp->l_value);
exit(EXIT_FAILURE);
@@ -1418,7 +1418,7 @@ rulesub(register struct rule *const rp,
rp->r_hiyear = rp->r_loyear;
break;
default: /* "cannot happen" */
- (void) fprintf(stderr,
+ fprintf(stderr,
_("%s: panic: Invalid l_value %d\n"),
progname, lp->l_value);
exit(EXIT_FAILURE);
@@ -1514,7 +1514,7 @@ puttzcode(const int_fast32_t val, FILE *const fp)
char buf[4];
convert(val, buf);
- (void) fwrite(buf, sizeof buf, 1, fp);
+ fwrite(buf, sizeof buf, 1, fp);
}
static void
@@ -1523,7 +1523,7 @@ puttzcode64(const zic_t val, FILE *const fp)
char buf[8];
convert64(val, buf);
- (void) fwrite(buf, sizeof buf, 1, fp);
+ fwrite(buf, sizeof buf, 1, fp);
}
static int
@@ -1561,7 +1561,7 @@ writezone(const char *const name, const char *const string, char version)
** Sort.
*/
if (timecnt > 1)
- (void) qsort(attypes, timecnt, sizeof *attypes, atcomp);
+ qsort(attypes, timecnt, sizeof *attypes, atcomp);
/*
** Optimize.
*/
@@ -1637,14 +1637,14 @@ writezone(const char *const name, const char *const string, char version)
}
fullname = erealloc(fullname,
strlen(directory) + 1 + strlen(name) + 1);
- (void) sprintf(fullname, "%s/%s", directory, name);
+ sprintf(fullname, "%s/%s", directory, name);
/*
** Remove old file, if any, to snap links.
*/
if (itsdir(fullname) <= 0 && remove(fullname) != 0 && errno != ENOENT) {
const char *e = strerror(errno);
- (void) fprintf(stderr, _("%s: Can't remove %s: %s\n"),
+ fprintf(stderr, _("%s: Can't remove %s: %s\n"),
progname, fullname, e);
exit(EXIT_FAILURE);
}
@@ -1654,7 +1654,7 @@ writezone(const char *const name, const char *const string, char version)
if ((fp = fopen(fullname, "wb")) == NULL) {
const char *e = strerror(errno);
- (void) fprintf(stderr, _("%s: Can't create %s: %s\n"),
+ fprintf(stderr, _("%s: Can't create %s: %s\n"),
progname, fullname, e);
exit(EXIT_FAILURE);
}
@@ -1767,15 +1767,15 @@ writezone(const char *const name, const char *const string, char version)
if (strcmp(&thischars[j], thisabbr) == 0)
break;
if (j == thischarcnt) {
- (void) strcpy(&thischars[(int) thischarcnt],
+ strcpy(&thischars[(int) thischarcnt],
thisabbr);
thischarcnt += strlen(thisabbr) + 1;
}
indmap[abbrinds[i]] = j;
}
-#define DO(field) ((void) fwrite(tzh.field, sizeof tzh.field, 1, fp))
+#define DO(field) fwrite(tzh.field, sizeof tzh.field, 1, fp)
tzh = tzh0;
- (void) strncpy(tzh.tzh_magic, TZ_MAGIC, sizeof tzh.tzh_magic);
+ strncpy(tzh.tzh_magic, TZ_MAGIC, sizeof tzh.tzh_magic);
tzh.tzh_version[0] = version;
convert(thistypecnt, tzh.tzh_ttisgmtcnt);
convert(thistypecnt, tzh.tzh_ttisstdcnt);
@@ -1806,16 +1806,16 @@ writezone(const char *const name, const char *const string, char version)
unsigned char uc;
uc = typemap[types[i]];
- (void) fwrite(&uc, sizeof uc, 1, fp);
+ fwrite(&uc, sizeof uc, 1, fp);
}
for (i = 0; i < typecnt; ++i)
if (writetype[i]) {
puttzcode(gmtoffs[i], fp);
- (void) putc(isdsts[i], fp);
- (void) putc((unsigned char) indmap[abbrinds[i]], fp);
+ putc(isdsts[i], fp);
+ putc((unsigned char) indmap[abbrinds[i]], fp);
}
if (thischarcnt != 0)
- (void) fwrite(thischars, sizeof thischars[0],
+ fwrite(thischars, sizeof thischars[0],
thischarcnt, fp);
for (i = thisleapi; i < thisleaplim; ++i) {
register zic_t todo;
@@ -1844,14 +1844,14 @@ writezone(const char *const name, const char *const string, char version)
}
for (i = 0; i < typecnt; ++i)
if (writetype[i])
- (void) putc(ttisstds[i], fp);
+ putc(ttisstds[i], fp);
for (i = 0; i < typecnt; ++i)
if (writetype[i])
- (void) putc(ttisgmts[i], fp);
+ putc(ttisgmts[i], fp);
}
- (void) fprintf(fp, "\n%s\n", string);
+ fprintf(fp, "\n%s\n", string);
if (ferror(fp) || fclose(fp)) {
- (void) fprintf(stderr, _("%s: Error writing %s\n"),
+ fprintf(stderr, _("%s: Error writing %s\n"),
progname, fullname);
exit(EXIT_FAILURE);
}
@@ -1869,13 +1869,13 @@ doabbr(char *const abbr, const char *const format, const char *const letters,
slashp = strchr(format, '/');
if (slashp == NULL) {
if (letters == NULL)
- (void) strcpy(abbr, format);
- else (void) sprintf(abbr, format, letters);
+ strcpy(abbr, format);
+ else sprintf(abbr, format, letters);
} else if (isdst) {
- (void) strcpy(abbr, slashp + 1);
+ strcpy(abbr, slashp + 1);
} else {
if (slashp > format)
- (void) strncpy(abbr, format, slashp - format);
+ strncpy(abbr, format, slashp - format);
abbr[slashp - format] = '\0';
}
if (!doquotes)
@@ -1910,7 +1910,7 @@ stringoffset(char *result, zic_t offset)
result[0] = '\0';
if (offset < 0) {
- (void) strcpy(result, "-");
+ strcpy(result, "-");
offset = -offset;
}
seconds = offset % SECSPERMIN;
@@ -1922,11 +1922,11 @@ stringoffset(char *result, zic_t offset)
result[0] = '\0';
return -1;
}
- (void) sprintf(end(result), "%d", hours);
+ sprintf(end(result), "%d", hours);
if (minutes != 0 || seconds != 0) {
- (void) sprintf(end(result), ":%02d", minutes);
+ sprintf(end(result), ":%02d", minutes);
if (seconds != 0)
- (void) sprintf(end(result), ":%02d", seconds);
+ sprintf(end(result), ":%02d", seconds);
}
return 0;
}
@@ -1949,9 +1949,9 @@ stringrule(char *result, const struct rule *const rp, const zic_t dstoff,
total += len_months[0][month];
/* Omit the "J" in Jan and Feb, as that's shorter. */
if (rp->r_month <= 1)
- (void) sprintf(result, "%d", total + rp->r_dayofmonth - 1);
+ sprintf(result, "%d", total + rp->r_dayofmonth - 1);
else
- (void) sprintf(result, "J%d", total + rp->r_dayofmonth);
+ sprintf(result, "J%d", total + rp->r_dayofmonth);
} else {
register int week;
register int wday = rp->r_wday;
@@ -1978,7 +1978,7 @@ stringrule(char *result, const struct rule *const rp, const zic_t dstoff,
} else return -1; /* "cannot happen" */
if (wday < 0)
wday += DAYSPERWEEK;
- (void) sprintf(result, "M%d.%d.%d",
+ sprintf(result, "M%d.%d.%d",
rp->r_month + 1, week, wday);
}
if (rp->r_todisgmt)
@@ -1986,7 +1986,7 @@ stringrule(char *result, const struct rule *const rp, const zic_t dstoff,
if (rp->r_todisstd && rp->r_stdoff == 0)
tod += dstoff;
if (tod != 2 * SECSPERMIN * MINSPERHOUR) {
- (void) strcat(result, "/");
+ strcat(result, "/");
if (stringoffset(end(result), tod) != 0)
return -1;
if (tod < 0) {
@@ -2108,7 +2108,7 @@ stringzone(char *result, const struct zone *const zpfirst, const int zonecount)
result[0] = '\0';
return -1;
}
- (void) strcat(result, ",");
+ strcat(result, ",");
c = stringrule(result, dstrp, dstrp->r_stdoff, zp->z_gmtoff);
if (c < 0) {
result[0] = '\0';
@@ -2116,7 +2116,7 @@ stringzone(char *result, const struct zone *const zpfirst, const int zonecount)
}
if (compat < c)
compat = c;
- (void) strcat(result, ",");
+ strcat(result, ",");
c = stringrule(result, stdrp, dstrp->r_stdoff, zp->z_gmtoff);
if (c < 0) {
result[0] = '\0';
@@ -2383,7 +2383,7 @@ outzone(const struct zone * const zpfirst, const int zonecount)
zp->z_format != NULL &&
strchr(zp->z_format, '%') == NULL &&
strchr(zp->z_format, '/') == NULL)
- (void) strcpy(startbuf, zp->z_format);
+ strcpy(startbuf, zp->z_format);
eat(zp->z_filename, zp->z_linenum);
if (*startbuf == '\0')
error(_("can't determine time zone abbreviation to use just after until time"));
@@ -2460,7 +2460,7 @@ addtt(const zic_t starttime, int type)
ttisstds[0] = ttisstds[type];
ttisgmts[0] = ttisgmts[type];
if (abbrinds[type] != 0)
- (void) strcpy(chars, &chars[abbrinds[type]]);
+ strcpy(chars, &chars[abbrinds[type]]);
abbrinds[0] = 0;
charcnt = strlen(chars) + 1;
typecnt = 1;
@@ -2583,7 +2583,7 @@ yearistype(const int year, const char *const type)
if (type == NULL || *type == '\0')
return TRUE;
buf = erealloc(buf, 132 + strlen(yitcommand) + strlen(type));
- (void) sprintf(buf, "%s %d %s", yitcommand, year, type);
+ sprintf(buf, "%s %d %s", yitcommand, year, type);
result = system(buf);
if (WIFEXITED(result)) switch (WEXITSTATUS(result)) {
case 0:
@@ -2592,7 +2592,7 @@ yearistype(const int year, const char *const type)
return FALSE;
}
error(_("Wild result from command execution"));
- (void) fprintf(stderr, _("%s: command was '%s', result was %d\n"),
+ fprintf(stderr, _("%s: command was '%s', result was %d\n"),
progname, buf, result);
for ( ; ; )
exit(EXIT_FAILURE);
@@ -2888,7 +2888,7 @@ mp = _("time zone abbreviation differs from POSIX standard");
error(_("too many, or too long, time zone abbreviations"));
exit(EXIT_FAILURE);
}
- (void) strcpy(&chars[charcnt], string);
+ strcpy(&chars[charcnt], string);
charcnt += i;
}
@@ -2920,7 +2920,7 @@ mkdirs(char *argname)
if (mkdir(name, MKDIR_UMASK) != 0) {
int err = errno;
if (itsdir(name) <= 0) {
- (void) fprintf(stderr,
+ fprintf(stderr,
_("%s: Can't create directory"
" %s: %s\n"),
progname, name, strerror(err));
--
1.9.1
2
6
The tz source code predates C99 and so used int, 0 and 1 for boolean,
but nowadays bool is available and makes the code clearer.
Include backwards-compatibility definitions for pre-C99 platforms,
and don't go beyond what the backwards-compatibility defintions support.
* date.c (main, reset, sametm, convert, checkfinal, iffy, netsettime):
* localtime.c (struct ttinfo, struct state, gmt_is_set)
(differ_by_repeat, tzload, typesequiv, getoffset, transtime)
(tzparse, gmtload, tzsetwall_unlocked, tzset_unlocked, gmtcheck)
(localtime_tzset, timesub, increment_overflow)
(increment_overflow32, increment_overflow_time)
(normalize_overflow, normalize_overflow32, time2sub, time2)
(time1):
* strftime.c (_fmt, _yconv, _loc):
* zdump.c (warned, errout, is_alpha, my_localtime, abbrok)
(main, hunt, show):
* zic.c (struct rule, errors, warnings, leapseen, noise)
(leap_types, ttisstds, ttisgmts, error, warning, main, dolink)
(associate, infile, gethms, inzone, inzcont, inzsub, inleap)
(rulesub, is32, writezone, doabbr, stringoffset, stringrule)
(stringzone, outzone, addtype, leapadd, yearistype, is_space)
(is_alpha, ciequal, itsabbr, mkdirs):
Use bool for boolean.
* localtime.c (tzload, tzparse):
* zic.c (stringoffset, mkdirs):
Return true for success and false for failure instead of 0 and -1.
All callers changed.
* private.h, zdump.c (TRUE, FALSE): Remove, replacing by ...
(true, false, bool): Define by <stdbool.h> if C99 or later,
by macros otherwise.
* tzfile.h: Remove mention of TRUE and FALSE from commentary.
* zic.c (addtype): Remove now-unnecessary checks that a bool is a
boolean.
---
date.c | 63 +++++++--------
localtime.c | 193 ++++++++++++++++++++++----------------------
private.h | 14 ++--
strftime.c | 26 +++---
tzfile.h | 8 +-
zdump.c | 58 +++++++-------
zic.c | 262 ++++++++++++++++++++++++++++--------------------------------
7 files changed, 304 insertions(+), 320 deletions(-)
diff --git a/date.c b/date.c
index c2a39f2..c8fab75 100644
--- a/date.c
+++ b/date.c
@@ -54,7 +54,7 @@ extern char * tzname[2];
static int retval = EXIT_SUCCESS;
-static void checkfinal(const char *, int, time_t, time_t);
+static void checkfinal(char const *, bool, time_t, time_t);
static time_t convert(const char *, int, time_t);
static void display(const char *, time_t);
static void dogmt(void);
@@ -75,12 +75,12 @@ main(const int argc, char *argv[])
register const char * value;
register const char * cp;
register int ch;
- register int dousg;
- register int aflag = 0;
- register int dflag = 0;
- register int nflag = 0;
- register int tflag = 0;
- register int rflag = 0;
+ register bool dousg;
+ register bool aflag = false;
+ register bool dflag = false;
+ register bool nflag = false;
+ register bool tflag = false;
+ register bool rflag = false;
register int minuteswest;
register int dsttime;
register double adjust;
@@ -115,7 +115,7 @@ main(const int argc, char *argv[])
_("date: error: multiple -r's used"));
usage();
}
- rflag = 1;
+ rflag = true;
errno = 0;
secs = strtoimax (optarg, &endarg, 0);
if (*endarg || optarg == endarg)
@@ -130,7 +130,7 @@ main(const int argc, char *argv[])
t = secs;
break;
case 'n': /* don't set network */
- nflag = 1;
+ nflag = true;
break;
case 'd': /* daylight saving time */
if (dflag) {
@@ -138,7 +138,7 @@ main(const int argc, char *argv[])
_("date: error: multiple -d's used"));
usage();
}
- dflag = 1;
+ dflag = true;
cp = optarg;
dsttime = atoi(cp);
if (*cp == '\0' || *nondigit(cp) != '\0')
@@ -151,7 +151,7 @@ main(const int argc, char *argv[])
_("date: error: multiple -t's used"));
usage();
}
- tflag = 1;
+ tflag = true;
cp = optarg;
minuteswest = atoi(cp);
if (*cp == '+' || *cp == '-')
@@ -166,7 +166,7 @@ main(const int argc, char *argv[])
_("date: error: multiple -a's used"));
usage();
}
- aflag = 1;
+ aflag = true;
cp = optarg;
adjust = atof(cp);
if (*cp == '+' || *cp == '-')
@@ -208,9 +208,9 @@ _("date: error: multiple values in command line\n"));
** even if time_t's range all the way back to the thirteenth
** century. Do not change the order.
*/
- t = convert(value, (dousg = TRUE), now);
+ t = convert(value, (dousg = true), now);
if (t == -1)
- t = convert(value, (dousg = FALSE), now);
+ t = convert(value, (dousg = false), now);
if (t == -1) {
/*
** Out of range values,
@@ -231,9 +231,9 @@ _("date: error: multiple values in command line\n"));
_("out of range seconds given"));
}
dogmt();
- t = convert(value, FALSE, now);
+ t = convert(value, false, now);
if (t == -1)
- t = convert(value, TRUE, now);
+ t = convert(value, true, now);
wildinput(_("time"), value,
(t == -1) ?
_("out of range value given") :
@@ -334,7 +334,7 @@ dogmt(void)
/*ARGSUSED*/
static void
-reset(const time_t newt, const int nflag)
+reset(time_t newt, bool nflag)
{
register int fid;
time_t oldt;
@@ -433,14 +433,14 @@ extern int logwtmp();
#endif /* HAVE_SETTIMEOFDAY == 1 */
#ifdef TSP_SETDATE
-static int netsettime(struct timeval);
+static bool netsettime(struct timeval);
#endif
#ifndef TSP_SETDATE
/*ARGSUSED*/
#endif /* !defined TSP_SETDATE */
static void
-reset(const time_t newt, const int nflag)
+reset(time_t newt, bool nflag)
{
register const char * username;
static struct timeval tv; /* static so tv_usec is 0 */
@@ -578,7 +578,7 @@ timeout(FILE *const fp, const char *const format, const struct tm *tmp)
free(cp);
}
-static int
+static bool
sametm(register const struct tm *const atmp,
register const struct tm *const btmp)
{
@@ -598,7 +598,7 @@ sametm(register const struct tm *const atmp,
#define ATOI2(ar) (ar[0] - '0') * 10 + (ar[1] - '0'); ar += 2;
static time_t
-convert(register const char * const value, const int dousg, const time_t t)
+convert(char const *value, bool dousg, time_t t)
{
register const char * cp;
register const char * dotp;
@@ -705,10 +705,7 @@ convert(register const char * const value, const int dousg, const time_t t)
*/
static void
-checkfinal(const char * const value,
- const int didusg,
- const time_t t,
- const time_t oldnow)
+checkfinal(char const *value, bool didusg, time_t t, time_t oldnow)
{
time_t othert;
struct tm tm, *tmp;
@@ -776,7 +773,7 @@ iffy(const time_t thist, const time_t thatt,
const char * const value, const char * const reason)
{
struct tm *tmp;
- int dst;
+ bool dst;
fprintf(stderr, _("date: warning: ambiguous time \"%s\", %s.\n"),
value, reason);
@@ -788,7 +785,7 @@ iffy(const time_t thist, const time_t thatt,
%M\
%Y.%S\n"), tmp);
tmp = localtime(&thist);
- dst = tmp ? tmp->tm_isdst : 0;
+ dst = tmp && tmp->tm_isdst;
timeout(stderr, _("to get %c"), tmp);
fprintf(stderr, _(" (%s). Use\n"),
dst ? _("summer time") : _("standard time"));
@@ -797,7 +794,7 @@ iffy(const time_t thist, const time_t thatt,
%M\
%Y.%S\n"), tmp);
tmp = localtime(&thatt);
- dst = tmp ? tmp->tm_isdst : 0;
+ dst = tmp && tmp->tm_isdst;
timeout(stderr, _("to get %c"), tmp);
fprintf(stderr, _(" (%s).\n"),
dst ? _("summer time") : _("standard time"));
@@ -815,9 +812,9 @@ iffy(const time_t thist, const time_t thatt,
* If the timedaemon is in the master state, it performs the
* correction on all slaves. If it is in the slave state, it
* notifies the master that a correction is needed.
- * Returns 1 on success, 0 on failure.
+ * Return true on success.
*/
-static int
+static bool
netsettime(struct timeval ntv)
{
int s, length, port, timed_ack, found, err, waittime;
@@ -832,7 +829,7 @@ netsettime(struct timeval ntv)
if (! sp) {
fputs(_("udp/timed: unknown service\n"), stderr);
retval = 2;
- return (0);
+ return false;
}
dest.sin_port = sp->s_port;
dest.sin_family = AF_INET;
@@ -915,7 +912,7 @@ loop:
case TSP_DATEACK:
lose(s);
- return (1);
+ return true;
default:
fprintf(stderr,
@@ -931,6 +928,6 @@ loop:
bad:
lose(s);
retval = 2;
- return (0);
+ return false;
}
#endif /* defined TSP_SETDATE */
diff --git a/localtime.c b/localtime.c
index 58b3e6e..98faacd 100644
--- a/localtime.c
+++ b/localtime.c
@@ -92,10 +92,10 @@ static const char gmt[] = "GMT";
struct ttinfo { /* time type information */
int_fast32_t tt_gmtoff; /* UT offset in seconds */
- int tt_isdst; /* used to set tm_isdst */
+ bool tt_isdst; /* used to set tm_isdst */
int tt_abbrind; /* abbreviation list index */
- int tt_ttisstd; /* TRUE if transition is std time */
- int tt_ttisgmt; /* TRUE if transition is UT */
+ bool tt_ttisstd; /* transition is std time */
+ bool tt_ttisgmt; /* transition is UT */
};
struct lsinfo { /* leap second information */
@@ -117,8 +117,8 @@ struct state {
int timecnt;
int typecnt;
int charcnt;
- int goback;
- int goahead;
+ bool goback;
+ bool goahead;
time_t ats[TZ_MAX_TIMES];
unsigned char types[TZ_MAX_TIMES];
struct ttinfo ttis[TZ_MAX_TYPES];
@@ -141,13 +141,13 @@ struct rule {
#define MONTH_NTH_DAY_OF_WEEK 2 /* Mm.n.d = month, week, day of week */
static struct tm *gmtsub(time_t const *, int_fast32_t, struct tm *);
-static int increment_overflow(int *, int);
-static int increment_overflow_time(time_t *, int_fast32_t);
-static int normalize_overflow32(int_fast32_t *, int *, int);
+static bool increment_overflow(int *, int);
+static bool increment_overflow_time(time_t *, int_fast32_t);
+static bool normalize_overflow32(int_fast32_t *, int *, int);
static struct tm *timesub(time_t const *, int_fast32_t, struct state const *,
struct tm *);
-static int typesequiv(struct state const *, int, int);
-static int tzparse(char const *, struct state *, int);
+static bool typesequiv(struct state const *, int, int);
+static bool tzparse(char const *, struct state *, bool);
#ifdef ALL_STATE
static struct state * lclptr;
@@ -167,7 +167,7 @@ static struct state gmtmem;
static char lcl_TZname[TZ_STRLEN_MAX + 1];
static int VOLATILE lcl_is_set;
-static int VOLATILE gmt_is_set;
+static bool VOLATILE gmt_is_set;
char * tzname[2] = {
(char *) wildabbr,
@@ -281,7 +281,7 @@ settzname(void)
}
}
-static int
+static bool
differ_by_repeat(const time_t t1, const time_t t0)
{
if (TYPE_BIT(time_t) - TYPE_SIGNED(time_t) < SECSPERREPEAT_BITS)
@@ -289,9 +289,9 @@ differ_by_repeat(const time_t t1, const time_t t0)
return t1 - t0 == SECSPERREPEAT;
}
-static int
+static bool
tzload(register const char *name, register struct state *const sp,
- register const int doextend)
+ bool doextend)
{
register const char * p;
register int i;
@@ -322,12 +322,12 @@ tzload(register const char *name, register struct state *const sp,
};
register char *fullname;
register u_t *up;
- register int doaccess;
+ register bool doaccess;
register union local_storage *lsp;
#ifdef ALL_STATE
lsp = malloc(sizeof *lsp);
if (!lsp)
- return -1;
+ return false;
#else /* !defined ALL_STATE */
union local_storage ls;
lsp = &ls;
@@ -335,7 +335,7 @@ tzload(register const char *name, register struct state *const sp,
fullname = lsp->fullname;
up = &lsp->u.u;
- sp->goback = sp->goahead = FALSE;
+ sp->goback = sp->goahead = false;
if (! name) {
name = TZDEFAULT;
@@ -355,7 +355,7 @@ tzload(register const char *name, register struct state *const sp,
strcat(fullname, name);
/* Set doaccess if '.' (as in "../") shows up in name. */
if (strchr(name, '.'))
- doaccess = TRUE;
+ doaccess = true;
name = fullname;
}
if (doaccess && access(name, R_OK) != 0)
@@ -475,12 +475,11 @@ tzload(register const char *name, register struct state *const sp,
ttisp = &sp->ttis[i];
if (ttisstdcnt == 0)
- ttisp->tt_ttisstd = FALSE;
+ ttisp->tt_ttisstd = false;
else {
- ttisp->tt_ttisstd = *p++;
- if (ttisp->tt_ttisstd != TRUE &&
- ttisp->tt_ttisstd != FALSE)
+ if (*p != true && *p != false)
goto oops;
+ ttisp->tt_ttisstd = *p++;
}
}
for (i = 0; i < sp->typecnt; ++i) {
@@ -488,12 +487,11 @@ tzload(register const char *name, register struct state *const sp,
ttisp = &sp->ttis[i];
if (ttisgmtcnt == 0)
- ttisp->tt_ttisgmt = FALSE;
+ ttisp->tt_ttisgmt = false;
else {
- ttisp->tt_ttisgmt = *p++;
- if (ttisp->tt_ttisgmt != TRUE &&
- ttisp->tt_ttisgmt != FALSE)
+ if (*p != true && *p != false)
goto oops;
+ ttisp->tt_ttisgmt = *p++;
}
}
/*
@@ -514,12 +512,11 @@ tzload(register const char *name, register struct state *const sp,
up->buf[0] == '\n' && up->buf[nread - 1] == '\n' &&
sp->typecnt + 2 <= TZ_MAX_TYPES) {
struct state *ts = &lsp->u.st;
- register int result;
up->buf[nread - 1] = '\0';
- result = tzparse(&up->buf[1], ts, FALSE);
- if (result == 0 && ts->typecnt == 2 &&
- sp->charcnt + ts->charcnt <= TZ_MAX_CHARS) {
+ if (tzparse(&up->buf[1], ts, false)
+ && ts->typecnt == 2
+ && sp->charcnt + ts->charcnt <= TZ_MAX_CHARS) {
for (i = 0; i < 2; ++i)
ts->ttis[i].tt_abbrind +=
sp->charcnt;
@@ -549,7 +546,7 @@ tzload(register const char *name, register struct state *const sp,
for (i = 1; i < sp->timecnt; ++i)
if (typesequiv(sp, sp->types[i], sp->types[0]) &&
differ_by_repeat(sp->ats[i], sp->ats[0])) {
- sp->goback = TRUE;
+ sp->goback = true;
break;
}
for (i = sp->timecnt - 2; i >= 0; --i)
@@ -557,7 +554,7 @@ tzload(register const char *name, register struct state *const sp,
sp->types[i]) &&
differ_by_repeat(sp->ats[sp->timecnt - 1],
sp->ats[i])) {
- sp->goahead = TRUE;
+ sp->goahead = true;
break;
}
}
@@ -598,23 +595,23 @@ tzload(register const char *name, register struct state *const sp,
#ifdef ALL_STATE
free(up);
#endif /* defined ALL_STATE */
- return 0;
+ return true;
oops:
#ifdef ALL_STATE
free(up);
#endif /* defined ALL_STATE */
- return -1;
+ return false;
}
-static int
+static bool
typesequiv(const struct state *const sp, const int a, const int b)
{
- register int result;
+ register bool result;
if (sp == NULL ||
a < 0 || a >= sp->typecnt ||
b < 0 || b >= sp->typecnt)
- result = FALSE;
+ result = false;
else {
register const struct ttinfo * ap = &sp->ttis[a];
register const struct ttinfo * bp = &sp->ttis[b];
@@ -752,10 +749,10 @@ getsecs(register const char *strp, int_fast32_t *const secsp)
static const char *
getoffset(register const char *strp, int_fast32_t *const offsetp)
{
- register int neg = 0;
+ register bool neg = false;
if (*strp == '-') {
- neg = 1;
+ neg = true;
++strp;
} else if (*strp == '+')
++strp;
@@ -829,7 +826,7 @@ static int_fast32_t ATTRIBUTE_PURE
transtime(const int year, register const struct rule *const rulep,
const int_fast32_t offset)
{
- register int leapyear;
+ register bool leapyear;
register int_fast32_t value;
register int i;
int d, m1, yy0, yy1, yy2, dow;
@@ -916,9 +913,9 @@ transtime(const int year, register const struct rule *const rulep,
** appropriate.
*/
-static int
+static bool
tzparse(const char *name, register struct state *const sp,
- const int lastditch)
+ bool lastditch)
{
const char * stdname;
const char * dstname;
@@ -927,7 +924,7 @@ tzparse(const char *name, register struct state *const sp,
int_fast32_t stdoffset;
int_fast32_t dstoffset;
register char * cp;
- register int load_result;
+ register bool load_ok;
static struct ttinfo zttinfo;
stdname = name;
@@ -943,7 +940,7 @@ tzparse(const char *name, register struct state *const sp,
stdname = name;
name = getqzname(name, '>');
if (*name != '>')
- return (-1);
+ return false;
stdlen = name - stdname;
name++;
} else {
@@ -951,20 +948,20 @@ tzparse(const char *name, register struct state *const sp,
stdlen = name - stdname;
}
if (*name == '\0')
- return -1;
+ return false;
name = getoffset(name, &stdoffset);
if (name == NULL)
- return -1;
+ return false;
}
- load_result = tzload(TZDEFRULES, sp, FALSE);
- if (load_result != 0)
+ load_ok = tzload(TZDEFRULES, sp, false);
+ if (!load_ok)
sp->leapcnt = 0; /* so, we're off a little */
if (*name != '\0') {
if (*name == '<') {
dstname = ++name;
name = getqzname(name, '>');
if (*name != '>')
- return -1;
+ return false;
dstlen = name - dstname;
name++;
} else {
@@ -975,9 +972,9 @@ tzparse(const char *name, register struct state *const sp,
if (*name != '\0' && *name != ',' && *name != ';') {
name = getoffset(name, &dstoffset);
if (name == NULL)
- return -1;
+ return false;
} else dstoffset = stdoffset - SECSPERHOUR;
- if (*name == '\0' && load_result != 0)
+ if (*name == '\0' && !load_ok)
name = TZDEFRULESTRING;
if (*name == ',' || *name == ';') {
struct rule start;
@@ -989,23 +986,23 @@ tzparse(const char *name, register struct state *const sp,
++name;
if ((name = getrule(name, &start)) == NULL)
- return -1;
+ return false;
if (*name++ != ',')
- return -1;
+ return false;
if ((name = getrule(name, &end)) == NULL)
- return -1;
+ return false;
if (*name != '\0')
- return -1;
+ return false;
sp->typecnt = 2; /* standard time and DST */
/*
** Two transitions per year, from EPOCH_YEAR forward.
*/
sp->ttis[0] = sp->ttis[1] = zttinfo;
sp->ttis[0].tt_gmtoff = -dstoffset;
- sp->ttis[0].tt_isdst = 1;
+ sp->ttis[0].tt_isdst = true;
sp->ttis[0].tt_abbrind = stdlen + 1;
sp->ttis[1].tt_gmtoff = -stdoffset;
- sp->ttis[1].tt_isdst = 0;
+ sp->ttis[1].tt_isdst = false;
sp->ttis[1].tt_abbrind = 0;
sp->defaulttype = 0;
timecnt = 0;
@@ -1018,7 +1015,7 @@ tzparse(const char *name, register struct state *const sp,
int_fast32_t
yearsecs = (year_lengths[isleap(year)]
* SECSPERDAY);
- int reversed = endtime < starttime;
+ bool reversed = endtime < starttime;
if (reversed) {
int_fast32_t swap = starttime;
starttime = endtime;
@@ -1053,12 +1050,12 @@ tzparse(const char *name, register struct state *const sp,
register int_fast32_t theirstdoffset;
register int_fast32_t theirdstoffset;
register int_fast32_t theiroffset;
- register int isdst;
+ register bool isdst;
register int i;
register int j;
if (*name != '\0')
- return -1;
+ return false;
/*
** Initial values of theirstdoffset and theirdstoffset.
*/
@@ -1083,7 +1080,7 @@ tzparse(const char *name, register struct state *const sp,
/*
** Initially we're assumed to be in standard time.
*/
- isdst = FALSE;
+ isdst = false;
theiroffset = theirstdoffset;
/*
** Now juggle transition times and types
@@ -1127,10 +1124,10 @@ tzparse(const char *name, register struct state *const sp,
*/
sp->ttis[0] = sp->ttis[1] = zttinfo;
sp->ttis[0].tt_gmtoff = -stdoffset;
- sp->ttis[0].tt_isdst = FALSE;
+ sp->ttis[0].tt_isdst = false;
sp->ttis[0].tt_abbrind = 0;
sp->ttis[1].tt_gmtoff = -dstoffset;
- sp->ttis[1].tt_isdst = TRUE;
+ sp->ttis[1].tt_isdst = true;
sp->ttis[1].tt_abbrind = stdlen + 1;
sp->typecnt = 2;
sp->defaulttype = 0;
@@ -1141,7 +1138,7 @@ tzparse(const char *name, register struct state *const sp,
sp->timecnt = 0;
sp->ttis[0] = zttinfo;
sp->ttis[0].tt_gmtoff = -stdoffset;
- sp->ttis[0].tt_isdst = 0;
+ sp->ttis[0].tt_isdst = false;
sp->ttis[0].tt_abbrind = 0;
sp->defaulttype = 0;
}
@@ -1149,7 +1146,7 @@ tzparse(const char *name, register struct state *const sp,
if (dstlen != 0)
sp->charcnt += dstlen + 1;
if ((size_t) sp->charcnt > sizeof sp->chars)
- return -1;
+ return false;
cp = sp->chars;
strncpy(cp, stdname, stdlen);
cp += stdlen;
@@ -1158,14 +1155,14 @@ tzparse(const char *name, register struct state *const sp,
strncpy(cp, dstname, dstlen);
*(cp + dstlen) = '\0';
}
- return 0;
+ return true;
}
static void
gmtload(struct state *const sp)
{
- if (tzload(gmt, sp, TRUE) != 0)
- tzparse(gmt, sp, TRUE);
+ if (! tzload(gmt, sp, true))
+ tzparse(gmt, sp, true);
}
static void
@@ -1177,7 +1174,7 @@ tzsetwall_unlocked(void)
if (! lclptr)
lclptr = malloc(sizeof *lclptr);
#endif
- if (lclptr && tzload(NULL, lclptr, TRUE) != 0)
+ if (lclptr && ! tzload(NULL, lclptr, true))
gmtload(lclptr);
settzname();
lcl_is_set = -1;
@@ -1197,7 +1194,7 @@ tzsetwall(void)
static void
tzset_unlocked(void)
{
- int shortname;
+ bool shortname;
register char const *name = getenv("TZ");
if (!name) {
@@ -1221,12 +1218,12 @@ tzset_unlocked(void)
lclptr->leapcnt = 0; /* so, we're off a little */
lclptr->timecnt = 0;
lclptr->typecnt = 0;
- lclptr->ttis[0].tt_isdst = 0;
+ lclptr->ttis[0].tt_isdst = false;
lclptr->ttis[0].tt_gmtoff = 0;
lclptr->ttis[0].tt_abbrind = 0;
strcpy(lclptr->chars, gmt);
- } else if (tzload(name, lclptr, TRUE) != 0)
- if (name[0] == ':' || tzparse(name, lclptr, FALSE) != 0)
+ } else if (! tzload(name, lclptr, true))
+ if (name[0] == ':' || ! tzparse(name, lclptr, false))
gmtload(lclptr);
}
settzname();
@@ -1252,7 +1249,7 @@ gmtcheck(void)
#endif
if (gmtptr)
gmtload(gmtptr);
- gmt_is_set = TRUE;
+ gmt_is_set = true;
}
/*
@@ -1342,7 +1339,7 @@ localsub(const time_t *const timep, const int_fast32_t offset,
}
static struct tm *
-localtime_tzset(time_t const *timep, struct tm *tmp, int skip_tzset)
+localtime_tzset(time_t const *timep, struct tm *tmp, bool skip_tzset)
{
int err = lock();
if (err) {
@@ -1461,11 +1458,11 @@ timesub(const time_t *const timep, const int_fast32_t offset,
int y;
register const int * ip;
register int_fast64_t corr;
- register int hit;
+ register bool hit;
register int i;
corr = 0;
- hit = 0;
+ hit = false;
i = (sp == NULL) ? 0 : sp->leapcnt;
while (--i >= 0) {
lp = &sp->lsis[i];
@@ -1614,7 +1611,7 @@ ctime_r(const time_t *const timep, char *buf)
** Normalize logic courtesy Paul Eggert.
*/
-static int
+static bool
increment_overflow(int *const ip, int j)
{
register int const i = *ip;
@@ -1626,23 +1623,23 @@ increment_overflow(int *const ip, int j)
** or if j < INT_MIN - i; given i < 0, INT_MIN - i cannot overflow.
*/
if ((i >= 0) ? (j > INT_MAX - i) : (j < INT_MIN - i))
- return TRUE;
+ return true;
*ip += j;
- return FALSE;
+ return false;
}
-static int
+static bool
increment_overflow32(int_fast32_t *const lp, int const m)
{
register int_fast32_t const l = *lp;
if ((l >= 0) ? (m > INT_FAST32_MAX - l) : (m < INT_FAST32_MIN - l))
- return TRUE;
+ return true;
*lp += m;
- return FALSE;
+ return false;
}
-static int
+static bool
increment_overflow_time(time_t *tp, int_fast32_t j)
{
/*
@@ -1653,12 +1650,12 @@ increment_overflow_time(time_t *tp, int_fast32_t j)
if (! (j < 0
? (TYPE_SIGNED(time_t) ? time_t_min - j <= *tp : -1 - j < *tp)
: *tp <= time_t_max - j))
- return TRUE;
+ return true;
*tp += j;
- return FALSE;
+ return false;
}
-static int
+static bool
normalize_overflow(int *const tensptr, int *const unitsptr, const int base)
{
register int tensdelta;
@@ -1670,7 +1667,7 @@ normalize_overflow(int *const tensptr, int *const unitsptr, const int base)
return increment_overflow(tensptr, tensdelta);
}
-static int
+static bool
normalize_overflow32(int_fast32_t *const tensptr, int *const unitsptr,
const int base)
{
@@ -1703,8 +1700,8 @@ static time_t
time2sub(struct tm *const tmp,
struct tm *(*const funcp)(const time_t *, int_fast32_t, struct tm *),
const int_fast32_t offset,
- int *const okayp,
- const int do_norm_secs)
+ bool *okayp,
+ bool do_norm_secs)
{
register const struct state * sp;
register int dir;
@@ -1718,7 +1715,7 @@ time2sub(struct tm *const tmp,
time_t t;
struct tm yourtm, mytm;
- *okayp = FALSE;
+ *okayp = false;
yourtm = *tmp;
if (do_norm_secs) {
if (normalize_overflow(&yourtm.tm_min, &yourtm.tm_sec,
@@ -1871,7 +1868,7 @@ label:
return WRONG;
t = newt;
if ((*funcp)(&t, offset, tmp))
- *okayp = TRUE;
+ *okayp = true;
return t;
}
@@ -1879,7 +1876,7 @@ static time_t
time2(struct tm * const tmp,
struct tm * (*const funcp)(const time_t *, int_fast32_t, struct tm *),
const int_fast32_t offset,
- int *const okayp)
+ bool *okayp)
{
time_t t;
@@ -1888,8 +1885,8 @@ time2(struct tm * const tmp,
** (in case tm_sec contains a value associated with a leap second).
** If that fails, try with normalization of seconds.
*/
- t = time2sub(tmp, funcp, offset, okayp, FALSE);
- return *okayp ? t : time2sub(tmp, funcp, offset, okayp, TRUE);
+ t = time2sub(tmp, funcp, offset, okayp, false);
+ return *okayp ? t : time2sub(tmp, funcp, offset, okayp, true);
}
static time_t
@@ -1905,7 +1902,7 @@ time1(struct tm *const tmp,
register int nseen;
char seen[TZ_MAX_TYPES];
unsigned char types[TZ_MAX_TYPES];
- int okay;
+ bool okay;
if (tmp == NULL) {
errno = EINVAL;
@@ -1935,11 +1932,11 @@ time1(struct tm *const tmp,
if (sp == NULL)
return WRONG;
for (i = 0; i < sp->typecnt; ++i)
- seen[i] = FALSE;
+ seen[i] = false;
nseen = 0;
for (i = sp->timecnt - 1; i >= 0; --i)
if (!seen[sp->types[i]]) {
- seen[sp->types[i]] = TRUE;
+ seen[sp->types[i]] = true;
types[nseen++] = sp->types[i];
}
for (sameind = 0; sameind < nseen; ++sameind) {
diff --git a/private.h b/private.h
index 2389e37..529b1dc 100644
--- a/private.h
+++ b/private.h
@@ -365,13 +365,13 @@ const char * scheck(const char * string, const char * format);
** Finally, some convenience items.
*/
-#ifndef TRUE
-#define TRUE 1
-#endif /* !defined TRUE */
-
-#ifndef FALSE
-#define FALSE 0
-#endif /* !defined FALSE */
+#if __STDC_VERSION__ < 199901
+# define true 1
+# define false 0
+# define bool int
+#else
+# include <stdbool.h>
+#endif
#ifndef TYPE_BIT
#define TYPE_BIT(type) (sizeof (type) * CHAR_BIT)
diff --git a/strftime.c b/strftime.c
index 259c90a..8f75499 100644
--- a/strftime.c
+++ b/strftime.c
@@ -101,7 +101,7 @@ static char * _add(const char *, char *, const char *);
static char * _conv(int, const char *, char *, const char *);
static char * _fmt(const char *, const struct tm *, char *, const char *,
int *);
-static char * _yconv(int, int, int, int, char *, const char *);
+static char * _yconv(int, int, bool, bool, char *, char const *);
extern char * tzname[];
@@ -193,8 +193,8 @@ label:
** something completely different.
** (ado, 1993-05-24)
*/
- pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 0,
- pt, ptlim);
+ pt = _yconv(t->tm_year, TM_YEAR_BASE,
+ true, false, pt, ptlim);
continue;
case 'c':
{
@@ -422,9 +422,11 @@ label:
pt, ptlim);
else if (*format == 'g') {
*warnp = IN_ALL;
- pt = _yconv(year, base, 0, 1,
+ pt = _yconv(year, base,
+ false, true,
pt, ptlim);
- } else pt = _yconv(year, base, 1, 1,
+ } else pt = _yconv(year, base,
+ true, true,
pt, ptlim);
}
continue;
@@ -462,11 +464,13 @@ label:
continue;
case 'y':
*warnp = IN_ALL;
- pt = _yconv(t->tm_year, TM_YEAR_BASE, 0, 1,
+ pt = _yconv(t->tm_year, TM_YEAR_BASE,
+ false, true,
pt, ptlim);
continue;
case 'Y':
- pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 1,
+ pt = _yconv(t->tm_year, TM_YEAR_BASE,
+ true, true,
pt, ptlim);
continue;
case 'Z':
@@ -585,7 +589,7 @@ _add(const char *str, char *pt, const char *const ptlim)
*/
static char *
-_yconv(const int a, const int b, const int convert_top, const int convert_yy,
+_yconv(int a, int b, bool convert_top, bool convert_yy,
char *pt, const char *const ptlim)
{
register int lead;
@@ -621,7 +625,7 @@ _loc(void)
static char * locale_buf;
int fd;
- int oldsun; /* "...ain't got nothin' to do..." */
+ bool oldsun; /* "...ain't got nothin' to do..." */
char * lbuf;
char * name;
char * p;
@@ -659,14 +663,14 @@ _loc(void)
if (sizeof filename <
((sizeof locale_home) + namesize + (sizeof lc_time)))
goto no_locale;
- oldsun = 0;
+ oldsun = false;
sprintf(filename, "%s/%s/%s", locale_home, name, lc_time);
fd = open(filename, O_RDONLY);
if (fd < 0) {
/*
** Old Sun systems have a different naming and data convention.
*/
- oldsun = 1;
+ oldsun = true;
sprintf(filename, "%s/%s/%s", locale_home,
lc_time, name);
fd = open(filename, O_RDONLY);
diff --git a/tzfile.h b/tzfile.h
index 150f956..ebecd68 100644
--- a/tzfile.h
+++ b/tzfile.h
@@ -62,13 +62,13 @@ struct tzhead {
** tzh_leapcnt repetitions of
** one (char [4]) coded leap second transition times
** one (char [4]) total correction after above
-** tzh_ttisstdcnt (char)s indexed by type; if TRUE, transition
-** time is standard time, if FALSE,
+** tzh_ttisstdcnt (char)s indexed by type; if 1, transition
+** time is standard time, if 0,
** transition time is wall clock time
** if absent, transition times are
** assumed to be wall clock time
-** tzh_ttisgmtcnt (char)s indexed by type; if TRUE, transition
-** time is UT, if FALSE,
+** tzh_ttisgmtcnt (char)s indexed by type; if 1, transition
+** time is UT, if 0,
** transition time is local time
** if absent, transition times are
** assumed to be local time
diff --git a/zdump.c b/zdump.c
index 070ad3c..f476621 100644
--- a/zdump.c
+++ b/zdump.c
@@ -89,13 +89,13 @@ typedef long intmax_t;
#define MAX_STRING_LENGTH 1024
#endif /* !defined MAX_STRING_LENGTH */
-#ifndef TRUE
-#define TRUE 1
-#endif /* !defined TRUE */
-
-#ifndef FALSE
-#define FALSE 0
-#endif /* !defined FALSE */
+#if __STDC_VERSION__ < 199901
+# define true 1
+# define false 0
+# define bool int
+#else
+# include <stdbool.h>
+#endif
#ifndef EXIT_SUCCESS
#define EXIT_SUCCESS 0
@@ -209,24 +209,24 @@ static time_t const absolute_max_time =
: -1);
static size_t longest;
static char * progname;
-static int warned;
-static int errout;
+static bool warned;
+static bool errout;
static char *abbr(struct tm *);
static intmax_t delta(struct tm *, struct tm *) ATTRIBUTE_PURE;
static void dumptime(struct tm const *);
static time_t hunt(char *, time_t, time_t);
-static void show(char *, time_t, int);
+static void show(char *, time_t, bool);
static const char *tformat(void);
static time_t yeartot(intmax_t) ATTRIBUTE_PURE;
/* Is A an alphabetic character in the C locale? */
-static int
+static bool
is_alpha(char a)
{
switch (a) {
default:
- return 0;
+ return false;
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
@@ -235,7 +235,7 @@ is_alpha(char a)
case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
case 'v': case 'w': case 'x': case 'y': case 'z':
- return 1;
+ return true;
}
}
@@ -269,7 +269,7 @@ my_localtime(time_t *tp)
fprintf(stderr, " -> ");
fprintf(stderr, tformat(), t);
fprintf(stderr, "\n");
- errout = TRUE;
+ errout = true;
}
}
return tmp;
@@ -308,7 +308,7 @@ abbrok(const char *const abbrp, const char *const zone)
fprintf(stderr,
_("%s: warning: zone \"%s\" abbreviation \"%s\" %s\n"),
progname, zone, abbrp, wp);
- warned = errout = TRUE;
+ warned = errout = true;
}
static void
@@ -342,8 +342,8 @@ int
main(int argc, char *argv[])
{
register int i;
- register int vflag;
- register int Vflag;
+ register bool vflag;
+ register bool Vflag;
register char * cutarg;
register char * cuttimes;
register time_t cutlotime;
@@ -374,14 +374,14 @@ main(int argc, char *argv[])
} else if (strcmp(argv[i], "--help") == 0) {
usage(stdout, EXIT_SUCCESS);
}
- vflag = Vflag = 0;
+ vflag = Vflag = false;
cutarg = cuttimes = NULL;
for (;;)
switch (getopt(argc, argv, "c:t:vV")) {
case 'c': cutarg = optarg; break;
case 't': cuttimes = optarg; break;
- case 'v': vflag = 1; break;
- case 'V': Vflag = 1; break;
+ case 'v': vflag = true; break;
+ case 'V': Vflag = true; break;
case -1:
if (! (optind == argc - 1 && strcmp(argv[optind], "=") == 0))
goto arg_processing_done;
@@ -477,15 +477,15 @@ main(int argc, char *argv[])
strcpy(&fakeenv[0][3], argv[i]);
if (! (vflag | Vflag)) {
- show(argv[i], now, FALSE);
+ show(argv[i], now, false);
continue;
}
- warned = FALSE;
+ warned = false;
t = absolute_min_time;
if (!Vflag) {
- show(argv[i], t, TRUE);
+ show(argv[i], t, true);
t += SECSPERDAY;
- show(argv[i], t, TRUE);
+ show(argv[i], t, true);
}
if (t < cutlotime)
t = cutlotime;
@@ -523,9 +523,9 @@ main(int argc, char *argv[])
if (!Vflag) {
t = absolute_max_time;
t -= SECSPERDAY;
- show(argv[i], t, TRUE);
+ show(argv[i], t, true);
t += SECSPERDAY;
- show(argv[i], t, TRUE);
+ show(argv[i], t, true);
}
}
close_file(stdout, NULL);
@@ -614,8 +614,8 @@ hunt(char *name, time_t lot, time_t hit)
lotmp = tmp;
} else hit = t;
}
- show(name, lot, TRUE);
- show(name, hit, TRUE);
+ show(name, lot, true);
+ show(name, hit, true);
return hit;
}
@@ -645,7 +645,7 @@ delta(struct tm * newp, struct tm *oldp)
}
static void
-show(char *zone, time_t t, int v)
+show(char *zone, time_t t, bool v)
{
register struct tm * tmp;
diff --git a/zic.c b/zic.c
index d230663..73ae17d 100644
--- a/zic.c
+++ b/zic.c
@@ -41,8 +41,8 @@ struct rule {
zic_t r_loyear; /* for example, 1986 */
zic_t r_hiyear; /* for example, 1986 */
const char * r_yrtype;
- int r_lowasnum;
- int r_hiwasnum;
+ bool r_lowasnum;
+ bool r_hiwasnum;
int r_month; /* 0..11 */
@@ -51,10 +51,10 @@ struct rule {
int r_wday;
zic_t r_tod; /* time from midnight */
- int r_todisstd; /* above is standard time if TRUE */
- /* or wall clock time if FALSE */
- int r_todisgmt; /* above is GMT if TRUE */
- /* or local time if FALSE */
+ bool r_todisstd; /* above is standard time if 1 */
+ /* or wall clock time if 0 */
+ bool r_todisgmt; /* above is GMT if 1 */
+ /* or local time if 0 */
zic_t r_stdoff; /* offset from standard time */
const char * r_abbrvar; /* variable part of abbreviation */
@@ -102,26 +102,25 @@ extern int optind;
#endif
static void addtt(zic_t starttime, int type);
-static int addtype(zic_t gmtoff, const char * abbr, int isdst,
- int ttisstd, int ttisgmt);
-static void leapadd(zic_t t, int positive, int rolling, int count);
+static int addtype(zic_t, char const *, bool, bool, bool);
+static void leapadd(zic_t, bool, int, int);
static void adjleap(void);
static void associate(void);
static void dolink(const char * fromfield, const char * tofield);
static char ** getfields(char * buf);
static zic_t gethms(const char * string, const char * errstring,
- int signable);
+ bool);
static void infile(const char * filename);
static void inleap(char ** fields, int nfields);
static void inlink(char ** fields, int nfields);
static void inrule(char ** fields, int nfields);
static int inzcont(char ** fields, int nfields);
static int inzone(char ** fields, int nfields);
-static int inzsub(char ** fields, int nfields, int iscont);
+static bool inzsub(char **, int, bool);
static int itsdir(const char * name);
static int is_alpha(char a);
static char lowerit(char);
-static int mkdirs(char * filename);
+static bool mkdirs(char *);
static void newabbr(const char * abbr);
static zic_t oadd(zic_t t1, zic_t t2);
static void outzone(const struct zone * zp, int ntzones);
@@ -134,11 +133,11 @@ static zic_t tadd(zic_t t1, zic_t t2);
static int yearistype(int year, const char * type);
static int charcnt;
-static int errors;
-static int warnings;
+static bool errors;
+static bool warnings;
static const char * filename;
static int leapcnt;
-static int leapseen;
+static bool leapseen;
static zic_t leapminyear;
static zic_t leapmaxyear;
static int linenum;
@@ -146,7 +145,7 @@ static int max_abbrvar_len;
static int max_format_len;
static zic_t max_year;
static zic_t min_year;
-static int noise;
+static bool noise;
static const char * rfilename;
static int rlinenum;
static const char * progname;
@@ -322,8 +321,8 @@ static struct lookup const end_years[] = {
};
static struct lookup const leap_types[] = {
- { "Rolling", TRUE },
- { "Stationary", FALSE },
+ { "Rolling", true },
+ { "Stationary", false },
{ NULL, 0 }
};
@@ -343,8 +342,8 @@ static struct attype {
static zic_t gmtoffs[TZ_MAX_TYPES];
static char isdsts[TZ_MAX_TYPES];
static unsigned char abbrinds[TZ_MAX_TYPES];
-static char ttisstds[TZ_MAX_TYPES];
-static char ttisgmts[TZ_MAX_TYPES];
+static bool ttisstds[TZ_MAX_TYPES];
+static bool ttisgmts[TZ_MAX_TYPES];
static char chars[TZ_MAX_CHARS];
static zic_t trans[TZ_MAX_LEAPS];
static zic_t corr[TZ_MAX_LEAPS];
@@ -439,7 +438,7 @@ error(const char *const string, ...)
va_start(args, string);
verror(string, args);
va_end(args);
- errors = 1;
+ errors = true;
}
static void ATTRIBUTE_FORMAT((printf, 1, 2))
@@ -450,7 +449,7 @@ warning(const char *const string, ...)
va_start(args, string);
verror(string, args);
va_end(args);
- warnings = 1;
+ warnings = true;
}
static void
@@ -573,7 +572,7 @@ _("%s: More than one -L option specified\n"),
}
break;
case 'v':
- noise = TRUE;
+ noise = true;
break;
case 's':
warning(_("-s ignored\n"));
@@ -725,7 +724,7 @@ dolink(const char *const fromfield, const char *const tofield)
if (link(fromname, toname) != 0) {
int result;
- if (mkdirs(toname) != 0)
+ if (! mkdirs(toname))
exit(EXIT_FAILURE);
result = link(fromname, toname);
@@ -914,7 +913,7 @@ associate(void)
*/
eat(zp->z_filename, zp->z_linenum);
zp->z_stdoff = gethms(zp->z_rule, _("unruly zone"),
- TRUE);
+ true);
/*
** Note, though, that if there's no rule,
** a '%s' in the format is a bad thing.
@@ -935,7 +934,7 @@ infile(const char *name)
register char * cp;
register const struct lookup * lp;
register int nfields;
- register int wantcont;
+ register bool wantcont;
register int num;
char buf[BUFSIZ];
@@ -949,7 +948,7 @@ infile(const char *name)
progname, name, e);
exit(EXIT_FAILURE);
}
- wantcont = FALSE;
+ wantcont = false;
for (num = 1; ; ++num) {
eat(name, num);
if (fgets(buf, sizeof buf, fp) != buf)
@@ -980,14 +979,14 @@ infile(const char *name)
else switch ((int) (lp->l_value)) {
case LC_RULE:
inrule(fields, nfields);
- wantcont = FALSE;
+ wantcont = false;
break;
case LC_ZONE:
wantcont = inzone(fields, nfields);
break;
case LC_LINK:
inlink(fields, nfields);
- wantcont = FALSE;
+ wantcont = false;
break;
case LC_LEAP:
if (name != leapsec)
@@ -995,7 +994,7 @@ infile(const char *name)
_("%s: Leap line in non leap seconds file %s\n"),
progname, name);
else inleap(fields, nfields);
- wantcont = FALSE;
+ wantcont = false;
break;
default: /* "cannot happen" */
fprintf(stderr,
@@ -1020,7 +1019,7 @@ _("%s: panic: Invalid l_value %d\n"),
*/
static zic_t
-gethms(const char *string, const char *const errstring, const int signable)
+gethms(char const *string, char const *errstring, bool signable)
{
zic_t hh;
int mm, ss, sign;
@@ -1074,7 +1073,7 @@ inrule(register char **const fields, const int nfields)
}
r.r_filename = filename;
r.r_linenum = linenum;
- r.r_stdoff = gethms(fields[RF_STDOFF], _("invalid saved time"), TRUE);
+ r.r_stdoff = gethms(fields[RF_STDOFF], _("invalid saved time"), true);
rulesub(&r, fields[RF_LOYEAR], fields[RF_HIYEAR], fields[RF_COMMAND],
fields[RF_MONTH], fields[RF_DAY], fields[RF_TOD]);
r.r_name = ecpyalloc(fields[RF_NAME]);
@@ -1085,26 +1084,26 @@ inrule(register char **const fields, const int nfields)
rules[nrules++] = r;
}
-static int
+static bool
inzone(register char **const fields, const int nfields)
{
register int i;
if (nfields < ZONE_MINFIELDS || nfields > ZONE_MAXFIELDS) {
error(_("wrong number of fields on Zone line"));
- return FALSE;
+ return false;
}
if (strcmp(fields[ZF_NAME], TZDEFAULT) == 0 && lcltime != NULL) {
error(
_("\"Zone %s\" line and -l option are mutually exclusive"),
TZDEFAULT);
- return FALSE;
+ return false;
}
if (strcmp(fields[ZF_NAME], TZDEFRULES) == 0 && psxrules != NULL) {
error(
_("\"Zone %s\" line and -p option are mutually exclusive"),
TZDEFRULES);
- return FALSE;
+ return false;
}
for (i = 0; i < nzones; ++i)
if (zones[i].z_name != NULL &&
@@ -1114,30 +1113,30 @@ _("duplicate zone name %s (file \"%s\", line %d)"),
fields[ZF_NAME],
zones[i].z_filename,
zones[i].z_linenum);
- return FALSE;
+ return false;
}
- return inzsub(fields, nfields, FALSE);
+ return inzsub(fields, nfields, false);
}
-static int
+static bool
inzcont(register char **const fields, const int nfields)
{
if (nfields < ZONEC_MINFIELDS || nfields > ZONEC_MAXFIELDS) {
error(_("wrong number of fields on Zone continuation line"));
- return FALSE;
+ return false;
}
- return inzsub(fields, nfields, TRUE);
+ return inzsub(fields, nfields, true);
}
-static int
-inzsub(register char **const fields, const int nfields, const int iscont)
+static bool
+inzsub(char **fields, int nfields, bool iscont)
{
register char * cp;
static struct zone z;
register int i_gmtoff, i_rule, i_format;
register int i_untilyear, i_untilmonth;
register int i_untilday, i_untiltime;
- register int hasuntil;
+ register bool hasuntil;
if (iscont) {
i_gmtoff = ZFC_GMTOFF;
@@ -1160,11 +1159,11 @@ inzsub(register char **const fields, const int nfields, const int iscont)
}
z.z_filename = filename;
z.z_linenum = linenum;
- z.z_gmtoff = gethms(fields[i_gmtoff], _("invalid UT offset"), TRUE);
+ z.z_gmtoff = gethms(fields[i_gmtoff], _("invalid UT offset"), true);
if ((cp = strchr(fields[i_format], '%')) != 0) {
if (*++cp != 's' || strchr(cp, '%') != 0) {
error(_("invalid abbreviation format"));
- return FALSE;
+ return false;
}
}
z.z_rule = ecpyalloc(fields[i_rule]);
@@ -1194,7 +1193,7 @@ inzsub(register char **const fields, const int nfields, const int iscont)
error(_(
"Zone continuation line end time is not after end time of previous line"
));
- return FALSE;
+ return false;
}
}
zones = growalloc(zones, sizeof *zones, nzones, &nzones_alloc);
@@ -1234,7 +1233,7 @@ inleap(register char ** const fields, const int nfields)
leapmaxyear = year;
if (!leapseen || leapminyear > year)
leapminyear = year;
- leapseen = TRUE;
+ leapseen = true;
j = EPOCH_YEAR;
while (j != year) {
if (year > j) {
@@ -1273,23 +1272,23 @@ inleap(register char ** const fields, const int nfields)
return;
}
t = dayoff * SECSPERDAY;
- tod = gethms(fields[LP_TIME], _("invalid time of day"), FALSE);
+ tod = gethms(fields[LP_TIME], _("invalid time of day"), false);
cp = fields[LP_CORR];
{
- register int positive;
+ register bool positive;
int count;
if (strcmp(cp, "") == 0) { /* infile() turns "-" into "" */
- positive = FALSE;
+ positive = false;
count = 1;
} else if (strcmp(cp, "--") == 0) {
- positive = FALSE;
+ positive = false;
count = 2;
} else if (strcmp(cp, "+") == 0) {
- positive = TRUE;
+ positive = true;
count = 1;
} else if (strcmp(cp, "++") == 0) {
- positive = TRUE;
+ positive = true;
count = 2;
} else {
error(_("illegal CORRECTION field on Leap line"));
@@ -1354,32 +1353,32 @@ rulesub(register struct rule *const rp,
return;
}
rp->r_month = lp->l_value;
- rp->r_todisstd = FALSE;
- rp->r_todisgmt = FALSE;
+ rp->r_todisstd = false;
+ rp->r_todisgmt = false;
dp = ecpyalloc(timep);
if (*dp != '\0') {
ep = dp + strlen(dp) - 1;
switch (lowerit(*ep)) {
case 's': /* Standard */
- rp->r_todisstd = TRUE;
- rp->r_todisgmt = FALSE;
+ rp->r_todisstd = true;
+ rp->r_todisgmt = false;
*ep = '\0';
break;
case 'w': /* Wall */
- rp->r_todisstd = FALSE;
- rp->r_todisgmt = FALSE;
+ rp->r_todisstd = false;
+ rp->r_todisgmt = false;
*ep = '\0';
break;
case 'g': /* Greenwich */
case 'u': /* Universal */
case 'z': /* Zulu */
- rp->r_todisstd = TRUE;
- rp->r_todisgmt = TRUE;
+ rp->r_todisstd = true;
+ rp->r_todisgmt = true;
*ep = '\0';
break;
}
}
- rp->r_tod = gethms(dp, _("invalid time of day"), FALSE);
+ rp->r_tod = gethms(dp, _("invalid time of day"), false);
free(dp);
/*
** Year work.
@@ -1534,7 +1533,7 @@ atcomp(const void *avp, const void *bvp)
return (a < b) ? -1 : (a > b);
}
-static int
+static bool
is32(const zic_t x)
{
return INT32_MIN <= x && x <= INT32_MAX;
@@ -1648,7 +1647,7 @@ writezone(const char *const name, const char *const string, char version)
exit(EXIT_FAILURE);
}
if ((fp = fopen(fullname, "wb")) == NULL) {
- if (mkdirs(fullname) != 0)
+ if (! mkdirs(fullname))
exit(EXIT_FAILURE);
if ((fp = fopen(fullname, "wb")) == NULL) {
const char *e = strerror(errno);
@@ -1690,16 +1689,16 @@ writezone(const char *const name, const char *const string, char version)
** (32- or 64-bit) window.
*/
if (typecnt != 0)
- writetype[typecnt - 1] = TRUE;
+ writetype[typecnt - 1] = true;
} else {
for (i = thistimei - 1; i < thistimelim; ++i)
if (i >= 0)
- writetype[types[i]] = TRUE;
+ writetype[types[i]] = true;
/*
** For America/Godthab and Antarctica/Palmer
*/
if (thistimei == 0)
- writetype[0] = TRUE;
+ writetype[0] = true;
}
#ifndef LEAVE_SOME_PRE_2011_SYSTEMS_IN_THE_LURCH
/*
@@ -1729,22 +1728,22 @@ writezone(const char *const name, const char *const string, char version)
isdsts[mrudst] = -1;
type = addtype(gmtoffs[mrudst],
&chars[abbrinds[mrudst]],
- TRUE,
+ true,
ttisstds[mrudst],
ttisgmts[mrudst]);
- isdsts[mrudst] = TRUE;
- writetype[type] = TRUE;
+ isdsts[mrudst] = 1;
+ writetype[type] = true;
}
if (histd >= 0 && mrustd >= 0 && histd != mrustd &&
gmtoffs[histd] != gmtoffs[mrustd]) {
isdsts[mrustd] = -1;
type = addtype(gmtoffs[mrustd],
&chars[abbrinds[mrustd]],
- FALSE,
+ false,
ttisstds[mrustd],
ttisgmts[mrustd]);
- isdsts[mrustd] = FALSE;
- writetype[type] = TRUE;
+ isdsts[mrustd] = 0;
+ writetype[type] = true;
}
}
#endif /* !defined LEAVE_SOME_PRE_2011_SYSTEMS_IN_THE_LURCH */
@@ -1855,7 +1854,7 @@ writezone(const char *const name, const char *const string, char version)
static void
doabbr(char *const abbr, const char *const format, const char *const letters,
- const int isdst, const int doquotes)
+ bool isdst, bool doquotes)
{
register char * cp;
register char * slashp;
@@ -1896,7 +1895,7 @@ updateminmax(const zic_t x)
max_year = x;
}
-static int
+static bool
stringoffset(char *result, zic_t offset)
{
register int hours;
@@ -1915,7 +1914,7 @@ stringoffset(char *result, zic_t offset)
hours = offset;
if (hours >= HOURSPERDAY * DAYSPERWEEK) {
result[0] = '\0';
- return -1;
+ return false;
}
sprintf(end(result), "%d", hours);
if (minutes != 0 || seconds != 0) {
@@ -1923,7 +1922,7 @@ stringoffset(char *result, zic_t offset)
if (seconds != 0)
sprintf(end(result), ":%02d", seconds);
}
- return 0;
+ return true;
}
static int
@@ -1982,7 +1981,7 @@ stringrule(char *result, const struct rule *const rp, const zic_t dstoff,
tod += dstoff;
if (tod != 2 * SECSPERMIN * MINSPERHOUR) {
strcat(result, "/");
- if (stringoffset(end(result), tod) != 0)
+ if (! stringoffset(end(result), tod))
return -1;
if (tod < 0) {
if (compat < 2013)
@@ -2071,14 +2070,14 @@ stringzone(char *result, const struct zone *const zpfirst, const int zonecount)
dstr.r_dycode = DC_DOM;
dstr.r_dayofmonth = 1;
dstr.r_tod = 0;
- dstr.r_todisstd = dstr.r_todisgmt = FALSE;
+ dstr.r_todisstd = dstr.r_todisgmt = false;
dstr.r_stdoff = stdrp->r_stdoff;
dstr.r_abbrvar = stdrp->r_abbrvar;
stdr.r_month = TM_DECEMBER;
stdr.r_dycode = DC_DOM;
stdr.r_dayofmonth = 31;
stdr.r_tod = SECSPERDAY + stdrp->r_stdoff;
- stdr.r_todisstd = stdr.r_todisgmt = FALSE;
+ stdr.r_todisstd = stdr.r_todisgmt = false;
stdr.r_stdoff = 0;
stdr.r_abbrvar
= (stdabbrrp ? stdabbrrp->r_abbrvar : "");
@@ -2089,17 +2088,17 @@ stringzone(char *result, const struct zone *const zpfirst, const int zonecount)
if (stdrp == NULL && (zp->z_nrules != 0 || zp->z_stdoff != 0))
return -1;
abbrvar = (stdrp == NULL) ? "" : stdrp->r_abbrvar;
- doabbr(result, zp->z_format, abbrvar, FALSE, TRUE);
- if (stringoffset(end(result), -zp->z_gmtoff) != 0) {
+ doabbr(result, zp->z_format, abbrvar, false, true);
+ if (! stringoffset(end(result), -zp->z_gmtoff)) {
result[0] = '\0';
return -1;
}
if (dstrp == NULL)
return compat;
- doabbr(end(result), zp->z_format, dstrp->r_abbrvar, TRUE, TRUE);
+ doabbr(end(result), zp->z_format, dstrp->r_abbrvar, true, true);
if (dstrp->r_stdoff != SECSPERMIN * MINSPERHOUR)
- if (stringoffset(end(result),
- -(zp->z_gmtoff + dstrp->r_stdoff)) != 0) {
+ if (! stringoffset(end(result),
+ -(zp->z_gmtoff + dstrp->r_stdoff))) {
result[0] = '\0';
return -1;
}
@@ -2128,23 +2127,23 @@ outzone(const struct zone * const zpfirst, const int zonecount)
register const struct zone * zp;
register struct rule * rp;
register int i, j;
- register int usestart, useuntil;
+ register bool usestart, useuntil;
register zic_t starttime, untiltime;
register zic_t gmtoff;
register zic_t stdoff;
register zic_t year;
register zic_t startoff;
- register int startttisstd;
- register int startttisgmt;
+ register bool startttisstd;
+ register bool startttisgmt;
register int type;
register char * startbuf;
register char * ab;
register char * envvar;
register int max_abbr_len;
register int max_envvar_len;
- register int prodstic; /* all rules are min to max */
+ register bool prodstic; /* all rules are min to max */
register int compat;
- register int do_extend;
+ register bool do_extend;
register char version;
max_abbr_len = 2 + max_format_len + max_abbrvar_len;
@@ -2165,8 +2164,8 @@ outzone(const struct zone * const zpfirst, const int zonecount)
** Thanks to Earl Chew
** for noting the need to unconditionally initialize startttisstd.
*/
- startttisstd = FALSE;
- startttisgmt = FALSE;
+ startttisstd = false;
+ startttisgmt = false;
min_year = max_year = EPOCH_YEAR;
if (leapseen) {
updateminmax(leapminyear);
@@ -2183,7 +2182,7 @@ outzone(const struct zone * const zpfirst, const int zonecount)
if (rp->r_hiwasnum)
updateminmax(rp->r_hiyear);
if (rp->r_lowasnum || rp->r_hiwasnum)
- prodstic = FALSE;
+ prodstic = false;
}
}
/*
@@ -2264,13 +2263,13 @@ outzone(const struct zone * const zpfirst, const int zonecount)
if (zp->z_nrules == 0) {
stdoff = zp->z_stdoff;
doabbr(startbuf, zp->z_format,
- NULL, stdoff != 0, FALSE);
+ NULL, stdoff != 0, false);
type = addtype(oadd(zp->z_gmtoff, stdoff),
startbuf, stdoff != 0, startttisstd,
startttisgmt);
if (usestart) {
addtt(starttime, type);
- usestart = FALSE;
+ usestart = false;
} else addtt(big_bang_time, type);
} else for (year = min_year; year <= max_year; ++year) {
if (useuntil && year > zp->z_untilrule.r_hiyear)
@@ -2336,12 +2335,12 @@ outzone(const struct zone * const zpfirst, const int zonecount)
if (k < 0)
break; /* go on to next year */
rp = &zp->z_rules[k];
- rp->r_todo = FALSE;
+ rp->r_todo = false;
if (useuntil && ktime >= untiltime)
break;
stdoff = rp->r_stdoff;
if (usestart && ktime == starttime)
- usestart = FALSE;
+ usestart = false;
if (usestart) {
if (ktime < starttime) {
startoff = oadd(zp->z_gmtoff,
@@ -2349,7 +2348,7 @@ outzone(const struct zone * const zpfirst, const int zonecount)
doabbr(startbuf, zp->z_format,
rp->r_abbrvar,
rp->r_stdoff != 0,
- FALSE);
+ false);
continue;
}
if (*startbuf == '\0' &&
@@ -2359,14 +2358,14 @@ outzone(const struct zone * const zpfirst, const int zonecount)
zp->z_format,
rp->r_abbrvar,
rp->r_stdoff !=
- 0,
- FALSE);
+ false,
+ false);
}
}
eats(zp->z_filename, zp->z_linenum,
rp->r_filename, rp->r_linenum);
doabbr(ab, zp->z_format, rp->r_abbrvar,
- rp->r_stdoff != 0, FALSE);
+ rp->r_stdoff != 0, false);
offset = oadd(zp->z_gmtoff, rp->r_stdoff);
type = addtype(offset, ab, rp->r_stdoff != 0,
rp->r_todisstd, rp->r_todisgmt);
@@ -2469,23 +2468,10 @@ addtt(const zic_t starttime, int type)
}
static int
-addtype(const zic_t gmtoff, const char *const abbr, const int isdst,
- const int ttisstd, const int ttisgmt)
+addtype(zic_t gmtoff, char const *abbr, bool isdst, bool ttisstd, bool ttisgmt)
{
register int i, j;
- if (isdst != TRUE && isdst != FALSE) {
- error(_("internal error: addtype called with bad isdst"));
- exit(EXIT_FAILURE);
- }
- if (ttisstd != TRUE && ttisstd != FALSE) {
- error(_("internal error: addtype called with bad ttisstd"));
- exit(EXIT_FAILURE);
- }
- if (ttisgmt != TRUE && ttisgmt != FALSE) {
- error(_("internal error: addtype called with bad ttisgmt"));
- exit(EXIT_FAILURE);
- }
/*
** See if there's already an entry for this zone type.
** If so, just return its index.
@@ -2525,7 +2511,7 @@ addtype(const zic_t gmtoff, const char *const abbr, const int isdst,
}
static void
-leapadd(const zic_t t, const int positive, const int rolling, int count)
+leapadd(zic_t t, bool positive, int rolling, int count)
{
register int i, j;
@@ -2569,22 +2555,22 @@ adjleap(void)
}
}
-static int
+static bool
yearistype(const int year, const char *const type)
{
static char * buf;
int result;
if (type == NULL || *type == '\0')
- return TRUE;
+ return true;
buf = erealloc(buf, 132 + strlen(yitcommand) + strlen(type));
sprintf(buf, "%s %d %s", yitcommand, year, type);
result = system(buf);
if (WIFEXITED(result)) switch (WEXITSTATUS(result)) {
case 0:
- return TRUE;
+ return true;
case 1:
- return FALSE;
+ return false;
}
error(_("Wild result from command execution"));
fprintf(stderr, _("%s: command was '%s', result was %d\n"),
@@ -2594,24 +2580,24 @@ yearistype(const int year, const char *const type)
}
/* Is A a space character in the C locale? */
-static int
+static bool
is_space(char a)
{
switch (a) {
default:
- return 0;
+ return false;
case ' ': case '\f': case '\n': case '\r': case '\t': case '\v':
- return 1;
+ return true;
}
}
/* Is A an alphabetic character in the C locale? */
-static int
+static bool
is_alpha(char a)
{
switch (a) {
default:
- return 0;
+ return false;
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N':
case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U':
@@ -2620,7 +2606,7 @@ is_alpha(char a)
case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
case 'v': case 'w': case 'x': case 'y': case 'z':
- return 1;
+ return true;
}
}
@@ -2644,27 +2630,27 @@ lowerit(char a)
}
/* case-insensitive equality */
-static ATTRIBUTE_PURE int
+static ATTRIBUTE_PURE bool
ciequal(register const char *ap, register const char *bp)
{
while (lowerit(*ap) == lowerit(*bp++))
if (*ap++ == '\0')
- return TRUE;
- return FALSE;
+ return true;
+ return false;
}
-static ATTRIBUTE_PURE int
+static ATTRIBUTE_PURE bool
itsabbr(register const char *abbr, register const char *word)
{
if (lowerit(*abbr) != lowerit(*word))
- return FALSE;
+ return false;
++word;
while (*++abbr != '\0')
do {
if (*word == '\0')
- return FALSE;
+ return false;
} while (lowerit(*word++) != lowerit(*abbr));
- return TRUE;
+ return true;
}
static ATTRIBUTE_PURE const struct lookup *
@@ -2887,14 +2873,14 @@ mp = _("time zone abbreviation differs from POSIX standard");
charcnt += i;
}
-static int
+static bool
mkdirs(char *argname)
{
register char * name;
register char * cp;
if (argname == NULL || *argname == '\0')
- return 0;
+ return true;
cp = name = ecpyalloc(argname);
while ((cp = strchr(cp + 1, '/')) != 0) {
*cp = '\0';
@@ -2920,11 +2906,11 @@ mkdirs(char *argname)
" %s: %s\n"),
progname, name, e);
free(name);
- return -1;
+ return false;
}
}
*cp = '/';
}
free(name);
- return 0;
+ return true;
}
--
1.9.1
1
0
[PROPOSED PATCH] Port to GCC 3.4.6, which does not define __LONG_LONG_MIN__ on Irix.
by Paul Eggert Aug. 19, 2014
by Paul Eggert Aug. 19, 2014
Aug. 19, 2014
* private.h (INT_FAST64_MIN, INTMAX_MIN): Don't use
__LONG_LONG_MIN__ when defining backwards-compatibility workaround.
---
private.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/private.h b/private.h
index 38f3f43..9482790 100644
--- a/private.h
+++ b/private.h
@@ -144,7 +144,7 @@ typedef long long int_fast64_t;
# define INT_FAST64_MIN LLONG_MIN
# define INT_FAST64_MAX LLONG_MAX
# else
-# define INT_FAST64_MIN __LONG_LONG_MIN__
+# define INT_FAST64_MIN (-1 - __LONG_LONG_MAX__)
# define INT_FAST64_MAX __LONG_LONG_MAX__
# endif
# define SCNdFAST64 "lld"
@@ -182,7 +182,7 @@ typedef long long intmax_t;
# define INTMAX_MIN LLONG_MIN
# else
# define INTMAX_MAX __LONG_LONG_MAX__
-# define INTMAX_MIN __LONG_LONG_MIN__
+# define INTMAX_MIN (-1 - __LONG_LONG_MAX__)
# endif
# else
typedef long intmax_t;
--
1.9.1
1
0