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