Proposed changes to asctime.c, zdump.c, and localtime.c
Olson, Arthur David (NIH/NCI)
olsona at dc37a.nci.nih.gov
Thu Dec 30 13:48:56 UTC 2004
Thanks to Paul and Ken for the feedback on zdump.c. Here's the next
iteration; these changes are relative to the code now available via ftp.
--ado
------- zdump.c -------
*** /tmp/geta16007 Thu Dec 30 08:46:20 2004
--- /tmp/getb16007 Thu Dec 30 08:46:20 2004
***************
*** 1,4 ****
! static char elsieid[] = "@(#)zdump.c 7.57";
/*
** This code has been made independent of the rest of the time
--- 1,4 ----
! static char elsieid[] = "@(#)zdump.c 7.59";
/*
** This code has been made independent of the rest of the time
***************
*** 151,156 ****
--- 151,157 ----
static time_t hunt P((char * name, time_t lot, time_t hit));
static void setabsolutes();
static void show P((char * zone, time_t t, int v));
+ static const char * tformat P((void));
static time_t yeartot P((long y));
int
***************
*** 469,475 ****
if (v) {
tmp = gmtime(&t);
if (tmp == NULL) {
! (void) printf("%g", (double) t);
} else {
dumptime(tmp);
(void) printf(" UTC");
--- 470,476 ----
if (v) {
tmp = gmtime(&t);
if (tmp == NULL) {
! (void) printf(tformat(), t);
} else {
dumptime(tmp);
(void) printf(" UTC");
***************
*** 504,509 ****
--- 505,537 ----
return (result == NULL) ? &nada : result;
}
+ /*
+ ** The code below can fail on certain theoretical systems;
+ ** it works on all known real-world systems as of 2004-12-30.
+ */
+
+ static const char *
+ tformat()
+ {
+ if (0.5 == (time_t) 0.5) { /* floating */
+ if (sizeof (time_t) > sizeof (double))
+ return "%Lg";
+ return "%g";
+ }
+ if (0 > (time_t) -1) { /* signed */
+ if (sizeof (time_t) > sizeof (long))
+ return "%lld";
+ if (sizeof (time_t) > sizeof (int))
+ return "%ld";
+ return "%d";
+ }
+ if (sizeof (time_t) > sizeof (unsigned long))
+ return "%llu";
+ if (sizeof (time_t) > sizeof (unsigned int))
+ return "%lu";
+ return "%u";
+ }
+
static void
dumptime(timeptr)
register const struct tm * timeptr;
More information about the tz
mailing list