asctime.c revision 15927
1254885Sdumbbell 2254885Sdumbbell#ifndef lint 3254885Sdumbbell#ifndef NOID 4254885Sdumbbellstatic char elsieid[] = "@(#)asctime.c 7.5"; 5254885Sdumbbell#endif /* !defined NOID */ 6254885Sdumbbell#endif /* !defined lint */ 7254885Sdumbbell 8254885Sdumbbell/*LINTLIBRARY*/ 9254885Sdumbbell 10254885Sdumbbell#include "private.h" 11254885Sdumbbell#include "tzfile.h" 12254885Sdumbbell 13254885Sdumbbell/* 14254885Sdumbbell** A la X3J11, with core dump avoidance. 15254885Sdumbbell*/ 16254885Sdumbbell 17254885Sdumbbellchar * 18254885Sdumbbellasctime(timeptr) 19254885Sdumbbellregister const struct tm * timeptr; 20254885Sdumbbell{ 21254885Sdumbbell static const char wday_name[][3] = { 22254885Sdumbbell "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" 23254885Sdumbbell }; 24254885Sdumbbell static const char mon_name[][3] = { 25254885Sdumbbell "Jan", "Feb", "Mar", "Apr", "May", "Jun", 26254885Sdumbbell "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" 27254885Sdumbbell }; 28254885Sdumbbell /* 29254885Sdumbbell ** Big enough for something such as 30254885Sdumbbell ** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n 31254885Sdumbbell ** (two three-character abbreviations, five strings denoting integers, 32254885Sdumbbell ** three explicit spaces, two explicit colons, a newline, 33254885Sdumbbell ** and a trailing ASCII nul). 34254885Sdumbbell */ 35254885Sdumbbell static char result[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) + 36254885Sdumbbell 3 + 2 + 1 + 1]; 37254885Sdumbbell register const char * wn; 38254885Sdumbbell register const char * mn; 39254885Sdumbbell 40254885Sdumbbell if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK) 41254885Sdumbbell wn = "???"; 42254885Sdumbbell else wn = wday_name[timeptr->tm_wday]; 43254885Sdumbbell if (timeptr->tm_mon < 0 || timeptr->tm_mon >= MONSPERYEAR) 44254885Sdumbbell mn = "???"; 45254885Sdumbbell else mn = mon_name[timeptr->tm_mon]; 46254885Sdumbbell /* 47254885Sdumbbell ** The X3J11-suggested format is 48254885Sdumbbell ** "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %d\n" 49254885Sdumbbell ** Since the .2 in 02.2d is ignored, we drop it. 50254885Sdumbbell */ 51254885Sdumbbell (void) sprintf(result, "%.3s %.3s%3d %02d:%02d:%02d %d\n", 52254885Sdumbbell wn, mn, 53254885Sdumbbell timeptr->tm_mday, timeptr->tm_hour, 54254885Sdumbbell timeptr->tm_min, timeptr->tm_sec, 55254885Sdumbbell TM_YEAR_BASE + timeptr->tm_year); 56254885Sdumbbell return result; 57254885Sdumbbell} 58254885Sdumbbell