date.c
Olson, Arthur David (NIH/NCI)
olsona at dc37a.nci.nih.gov
Mon Nov 8 15:50:46 UTC 2004
Below find proposed changes to date.c to improve handling of locales and to
avoid overflow problems on systems with both 64-bit time_t values.
These are variations on Paul Eggert's theme.
--ado
------- date.c -------
*** /tmp/geta8752 Mon Nov 8 10:43:48 2004
--- /tmp/getb8752 Mon Nov 8 10:43:48 2004
***************
*** 1,6 ****
#ifndef lint
#ifndef NOID
! static char elsieid[] = "@(#)date.c 7.38";
/*
** Modified from the UCB version with the SCCS ID appearing below.
*/
--- 1,6 ----
#ifndef lint
#ifndef NOID
! static char elsieid[] = "@(#)date.c 7.40";
/*
** Modified from the UCB version with the SCCS ID appearing below.
*/
***************
*** 116,129 ****
INITIALIZE(dsttime);
INITIALIZE(adjust);
INITIALIZE(t);
! #if HAVE_GETTEXT - 0
! (void) setlocale(LC_MESSAGES, "");
#ifdef TZ_DOMAINDIR
(void) bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR);
#endif /* defined(TEXTDOMAINDIR) */
(void) textdomain(TZ_DOMAIN);
! #endif /* HAVE_GETTEXT - 0 */
! (void) setlocale(LC_TIME, "");
(void) time(&now);
format = value = NULL;
while ((ch = getopt(argc, argv, "ucnd:t:a:")) != EOF && ch != -1) {
--- 116,130 ----
INITIALIZE(dsttime);
INITIALIZE(adjust);
INITIALIZE(t);
! #ifdef LC_ALL
! (void) setlocale(LC_ALL, "");
! #endif /* defined(LC_ALL) */
! #if HAVE_GETTEXT
#ifdef TZ_DOMAINDIR
(void) bindtextdomain(TZ_DOMAIN, TZ_DOMAINDIR);
#endif /* defined(TEXTDOMAINDIR) */
(void) textdomain(TZ_DOMAIN);
! #endif /* HAVE_GETTEXT */
(void) time(&now);
format = value = NULL;
while ((ch = getopt(argc, argv, "ucnd:t:a:")) != EOF && ch != -1) {
***************
*** 630,637 ****
time_t outt;
tm = *localtime(&t);
! cent = (tm.tm_year + TM_YEAR_BASE) / 100;
! year_in_cent = (tm.tm_year + TM_YEAR_BASE) - cent * 100;
month = tm.tm_mon + 1;
day = tm.tm_mday;
hour = tm.tm_hour;
--- 631,645 ----
time_t outt;
tm = *localtime(&t);
! #define DIVISOR 100
! year_in_cent = tm.tm_year % DIVISOR + TM_YEAR_BASE % DIVISOR;
! cent = tm.tm_year / DIVISOR + TM_YEAR_BASE / DIVISOR +
! year_in_cent / DIVISOR;
! year_in_cent %= DIVISOR;
! if (year_in_cent < 0) {
! year_in_cent += DIVISOR;
! --cent;
! }
month = tm.tm_mon + 1;
day = tm.tm_mday;
hour = tm.tm_hour;
More information about the tz
mailing list