1996-06-05 08:01:54 -04:00
|
|
|
/*
|
|
|
|
|
** This file is in the public domain, so clarified as of
|
2005-12-08 11:35:31 -05:00
|
|
|
** 1996-06-05 by Arthur David Olson.
|
1996-06-05 08:01:54 -04:00
|
|
|
*/
|
|
|
|
|
|
2004-12-27 09:04:50 -05:00
|
|
|
/*
|
|
|
|
|
** Avoid the temptation to punt entirely to strftime;
|
|
|
|
|
** the output of strftime is supposed to be locale specific
|
|
|
|
|
** whereas the output of asctime is supposed to be constant.
|
|
|
|
|
*/
|
|
|
|
|
|
1988-02-18 04:31:35 -05:00
|
|
|
/*LINTLIBRARY*/
|
|
|
|
|
|
1989-03-21 11:37:00 -05:00
|
|
|
#include "private.h"
|
1986-12-31 16:13:33 -05:00
|
|
|
#include "tzfile.h"
|
1986-12-31 14:22:18 -05:00
|
|
|
|
2004-07-29 11:08:13 -04:00
|
|
|
/*
|
|
|
|
|
** Some systems only handle "%.2d"; others only handle "%02d";
|
|
|
|
|
** "%02.2d" makes (most) everybody happy.
|
2006-03-14 10:27:07 -05:00
|
|
|
** At least some versions of gcc warn about the %02.2d;
|
|
|
|
|
** we conditionalize below to avoid the warning.
|
2004-07-29 11:08:13 -04:00
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
** All years associated with 32-bit time_t values are exactly four digits long;
|
|
|
|
|
** some years associated with 64-bit time_t values are not.
|
|
|
|
|
** Vintage programs are coded for years that are always four digits long
|
|
|
|
|
** and may assume that the newline always lands in the same place.
|
|
|
|
|
** For years that are less than four digits, we pad the output with
|
2004-10-14 17:27:17 -04:00
|
|
|
** leading zeroes to get the newline in the traditional place.
|
2004-10-18 11:37:53 -04:00
|
|
|
** The -4 ensures that we get four characters of output even if
|
|
|
|
|
** we call a strftime variant that produces fewer characters for some years.
|
2004-10-18 17:28:09 -04:00
|
|
|
** The ISO C 1999 and POSIX 1003.1-2004 standards prohibit padding the year,
|
|
|
|
|
** but many implementations pad anyway; most likely the standards are buggy.
|
2004-07-29 11:08:13 -04:00
|
|
|
*/
|
2006-03-14 10:27:07 -05:00
|
|
|
#ifdef __GNUC__
|
|
|
|
|
#define ASCTIME_FMT "%.3s %.3s%3d %2.2d:%2.2d:%2.2d %-4s\n"
|
|
|
|
|
#else /* !defined __GNUC__ */
|
2004-10-11 16:21:05 -04:00
|
|
|
#define ASCTIME_FMT "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %-4s\n"
|
2006-03-14 10:27:07 -05:00
|
|
|
#endif /* !defined __GNUC__ */
|
2004-07-29 11:08:13 -04:00
|
|
|
/*
|
|
|
|
|
** For years that are more than four digits we put extra spaces before the year
|
|
|
|
|
** so that code trying to overwrite the newline won't end up overwriting
|
|
|
|
|
** a digit within a year and truncating the year (operating on the assumption
|
|
|
|
|
** that no output is better than wrong output).
|
|
|
|
|
*/
|
2006-03-14 10:27:07 -05:00
|
|
|
#ifdef __GNUC__
|
|
|
|
|
#define ASCTIME_FMT_B "%.3s %.3s%3d %2.2d:%2.2d:%2.2d %s\n"
|
|
|
|
|
#else /* !defined __GNUC__ */
|
2004-10-11 16:21:05 -04:00
|
|
|
#define ASCTIME_FMT_B "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %s\n"
|
2006-03-14 10:27:07 -05:00
|
|
|
#endif /* !defined __GNUC__ */
|
2004-07-29 11:08:13 -04:00
|
|
|
|
|
|
|
|
#define STD_ASCTIME_BUF_SIZE 26
|
|
|
|
|
/*
|
|
|
|
|
** Big enough for something such as
|
|
|
|
|
** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n
|
|
|
|
|
** (two three-character abbreviations, five strings denoting integers,
|
|
|
|
|
** seven explicit spaces, two explicit colons, a newline,
|
2014-06-28 14:09:32 -07:00
|
|
|
** and a trailing NUL byte).
|
2004-07-29 11:08:13 -04:00
|
|
|
** The values above are for systems where an int is 32 bits and are provided
|
2004-08-02 17:37:18 -04:00
|
|
|
** as an example; the define below calculates the maximum for the system at
|
|
|
|
|
** hand.
|
2004-07-29 11:08:13 -04:00
|
|
|
*/
|
|
|
|
|
#define MAX_ASCTIME_BUF_SIZE (2*3+5*INT_STRLEN_MAXIMUM(int)+7+2+1+1)
|
|
|
|
|
|
|
|
|
|
static char buf_asctime[MAX_ASCTIME_BUF_SIZE];
|
2004-07-26 15:23:32 -04:00
|
|
|
|
1986-12-31 14:22:18 -05:00
|
|
|
/*
|
2004-07-20 10:03:30 -04:00
|
|
|
** A la ISO/IEC 9945-1, ANSI/IEEE Std 1003.1, 2004 Edition.
|
1986-12-31 14:22:18 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
char *
|
Restore 'register'.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, nondigit, sametm, convert, checkfinal):
* ialloc.c (icatalloc):
* localtime.c (detzcode, detzcode64, settzname, tzload)
(typesequiv, getzname, getqzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, tzset, localsub, gmtsub)
(leaps_thru_end_of, timesub, increment_overflow)
(long_increment_overflow, normalize_overflow)
(long_normalize_overflow, tmcomp, time2sub, time1, leapcorr):
* scheck.c (scheck):
* strftime.c (_yconv):
* zdump.c (my_localtime, abbrok, main, yeartot, hunt)
(delta, show, abbr, dumptime):
* zic.c (main, dolink, itsdir, associate, infile, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert64)
(writezone, doabbr, stringoffset, stringrule, stringzone)
(outzone, addtype, leapadd, adjleap, ciequal, itsabbr, byword)
(getfields, rpytime, newabbr, mkdirs):
Restore the uses of 'register', reverting that part of the
"More C modernization" patch. See Arthur David Olson in
<http://mm.icann.org/pipermail/tz/2012-October/018385.html>.
2012-10-26 17:37:42 -07:00
|
|
|
asctime_r(register const struct tm *timeptr, char *buf)
|
1986-12-31 14:22:18 -05:00
|
|
|
{
|
1993-05-29 21:14:53 -04:00
|
|
|
static const char wday_name[][3] = {
|
1986-12-31 14:22:18 -05:00
|
|
|
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
|
|
|
|
|
};
|
1993-05-29 21:14:53 -04:00
|
|
|
static const char mon_name[][3] = {
|
1986-12-31 14:22:18 -05:00
|
|
|
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
|
|
|
|
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
|
|
|
|
};
|
Restore 'register'.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, nondigit, sametm, convert, checkfinal):
* ialloc.c (icatalloc):
* localtime.c (detzcode, detzcode64, settzname, tzload)
(typesequiv, getzname, getqzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, tzset, localsub, gmtsub)
(leaps_thru_end_of, timesub, increment_overflow)
(long_increment_overflow, normalize_overflow)
(long_normalize_overflow, tmcomp, time2sub, time1, leapcorr):
* scheck.c (scheck):
* strftime.c (_yconv):
* zdump.c (my_localtime, abbrok, main, yeartot, hunt)
(delta, show, abbr, dumptime):
* zic.c (main, dolink, itsdir, associate, infile, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert64)
(writezone, doabbr, stringoffset, stringrule, stringzone)
(outzone, addtype, leapadd, adjleap, ciequal, itsabbr, byword)
(getfields, rpytime, newabbr, mkdirs):
Restore the uses of 'register', reverting that part of the
"More C modernization" patch. See Arthur David Olson in
<http://mm.icann.org/pipermail/tz/2012-October/018385.html>.
2012-10-26 17:37:42 -07:00
|
|
|
register const char * wn;
|
|
|
|
|
register const char * mn;
|
2004-10-11 16:21:05 -04:00
|
|
|
char year[INT_STRLEN_MAXIMUM(int) + 2];
|
2004-07-29 11:08:13 -04:00
|
|
|
char result[MAX_ASCTIME_BUF_SIZE];
|
1986-12-31 14:22:18 -05:00
|
|
|
|
2010-02-06 12:59:20 -05:00
|
|
|
if (timeptr == NULL) {
|
|
|
|
|
errno = EINVAL;
|
2010-02-06 15:08:44 -05:00
|
|
|
return strcpy(buf, "??? ??? ?? ??:??:?? ????\n");
|
2010-02-06 12:59:20 -05:00
|
|
|
}
|
2004-08-09 19:50:18 -04:00
|
|
|
if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK)
|
1989-03-18 20:35:08 -05:00
|
|
|
wn = "???";
|
|
|
|
|
else wn = wday_name[timeptr->tm_wday];
|
2004-08-09 19:50:18 -04:00
|
|
|
if (timeptr->tm_mon < 0 || timeptr->tm_mon >= MONSPERYEAR)
|
1989-03-18 20:35:08 -05:00
|
|
|
mn = "???";
|
|
|
|
|
else mn = mon_name[timeptr->tm_mon];
|
2004-10-14 17:27:17 -04:00
|
|
|
/*
|
|
|
|
|
** Use strftime's %Y to generate the year, to avoid overflow problems
|
|
|
|
|
** when computing timeptr->tm_year + TM_YEAR_BASE.
|
|
|
|
|
** Assume that strftime is unaffected by other out-of-range members
|
|
|
|
|
** (e.g., timeptr->tm_mday) when processing "%Y".
|
|
|
|
|
*/
|
2014-08-18 19:10:48 -07:00
|
|
|
strftime(year, sizeof year, "%Y", timeptr);
|
2004-07-27 10:45:55 -04:00
|
|
|
/*
|
|
|
|
|
** We avoid using snprintf since it's not available on all systems.
|
|
|
|
|
*/
|
2014-08-18 19:10:48 -07:00
|
|
|
sprintf(result,
|
2004-10-11 16:21:05 -04:00
|
|
|
((strlen(year) <= 4) ? ASCTIME_FMT : ASCTIME_FMT_B),
|
1989-03-18 20:35:08 -05:00
|
|
|
wn, mn,
|
1986-12-31 14:22:18 -05:00
|
|
|
timeptr->tm_mday, timeptr->tm_hour,
|
|
|
|
|
timeptr->tm_min, timeptr->tm_sec,
|
2004-07-29 11:08:13 -04:00
|
|
|
year);
|
2010-02-06 15:08:44 -05:00
|
|
|
if (strlen(result) < STD_ASCTIME_BUF_SIZE || buf == buf_asctime)
|
|
|
|
|
return strcpy(buf, result);
|
|
|
|
|
else {
|
2004-07-29 11:08:13 -04:00
|
|
|
errno = EOVERFLOW;
|
|
|
|
|
return NULL;
|
2004-07-26 15:23:32 -04:00
|
|
|
}
|
1998-05-25 12:59:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2004-07-27 10:45:55 -04:00
|
|
|
** A la ISO/IEC 9945-1, ANSI/IEEE Std 1003.1, 2004 Edition.
|
1998-05-25 12:59:36 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
char *
|
Restore 'register'.
* asctime.c (asctime_r, asctime):
* date.c (main, dogmt, reset, nondigit, sametm, convert, checkfinal):
* ialloc.c (icatalloc):
* localtime.c (detzcode, detzcode64, settzname, tzload)
(typesequiv, getzname, getqzname, getnum, getsecs, getoffset)
(getrule, transtime, tzparse, tzset, localsub, gmtsub)
(leaps_thru_end_of, timesub, increment_overflow)
(long_increment_overflow, normalize_overflow)
(long_normalize_overflow, tmcomp, time2sub, time1, leapcorr):
* scheck.c (scheck):
* strftime.c (_yconv):
* zdump.c (my_localtime, abbrok, main, yeartot, hunt)
(delta, show, abbr, dumptime):
* zic.c (main, dolink, itsdir, associate, infile, inrule)
(inzone, inzcont, inzsub, inleap, inlink, rulesub, convert64)
(writezone, doabbr, stringoffset, stringrule, stringzone)
(outzone, addtype, leapadd, adjleap, ciequal, itsabbr, byword)
(getfields, rpytime, newabbr, mkdirs):
Restore the uses of 'register', reverting that part of the
"More C modernization" patch. See Arthur David Olson in
<http://mm.icann.org/pipermail/tz/2012-October/018385.html>.
2012-10-26 17:37:42 -07:00
|
|
|
asctime(register const struct tm *timeptr)
|
1998-05-25 12:59:36 -04:00
|
|
|
{
|
2004-07-29 11:08:13 -04:00
|
|
|
return asctime_r(timeptr, buf_asctime);
|
1986-12-31 14:22:18 -05:00
|
|
|
}
|