asctime.c revision 2708
1#ifndef lint 2#ifndef NOID 3static char elsieid[] = "@(#)asctime.c 7.5"; 4#endif /* !defined NOID */ 5#endif /* !defined lint */ 6 7/*LINTLIBRARY*/ 8 9#include "private.h" 10#include "tzfile.h" 11 12/* 13** A la X3J11, with core dump avoidance. 14*/ 15 16char * 17asctime(timeptr) 18register const struct tm * timeptr; 19{ 20 static const char wday_name[][3] = { 21 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" 22 }; 23 static const char mon_name[][3] = { 24 "Jan", "Feb", "Mar", "Apr", "May", "Jun", 25 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" 26 }; 27 /* 28 ** Big enough for something such as 29 ** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n 30 ** (two three-character abbreviations, five strings denoting integers, 31 ** three explicit spaces, two explicit colons, a newline, 32 ** and a trailing ASCII nul). 33 */ 34 static char result[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) + 35 3 + 2 + 1 + 1]; 36 register const char * wn; 37 register const char * mn; 38 39 if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK) 40 wn = "???"; 41 else wn = wday_name[timeptr->tm_wday]; 42 if (timeptr->tm_mon < 0 || timeptr->tm_mon >= MONSPERYEAR) 43 mn = "???"; 44 else mn = mon_name[timeptr->tm_mon]; 45 /* 46 ** The X3J11-suggested format is 47 ** "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %d\n" 48 ** Since the .2 in 02.2d is ignored, we drop it. 49 */ 50 (void) sprintf(result, "%.3s %.3s%3d %02d:%02d:%02d %d\n", 51 wn, mn, 52 timeptr->tm_mday, timeptr->tm_hour, 53 timeptr->tm_min, timeptr->tm_sec, 54 TM_YEAR_BASE + timeptr->tm_year); 55 return result; 56} 57