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