asctime.c revision 71579
1300829Sgrehan/* 2300829Sgrehan** This file is in the public domain, so clarified as of 3300829Sgrehan** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov). 4300829Sgrehan* 5300829Sgrehan* $FreeBSD: head/lib/libc/stdtime/asctime.c 71579 2001-01-24 13:01:12Z deischen $ 6300829Sgrehan*/ 7300829Sgrehan 8300829Sgrehan#ifndef lint 9300829Sgrehan#ifndef NOID 10300829Sgrehanstatic char elsieid[] = "@(#)asctime.c 7.7"; 11300829Sgrehan#endif /* !defined NOID */ 12300829Sgrehan#endif /* !defined lint */ 13300829Sgrehan 14300829Sgrehan/*LINTLIBRARY*/ 15300829Sgrehan 16300829Sgrehan#include "namespace.h" 17300829Sgrehan#include "private.h" 18300829Sgrehan#include "un-namespace.h" 19300829Sgrehan#include "tzfile.h" 20300829Sgrehan 21300829Sgrehan/* 22300829Sgrehan** A la X3J11, with core dump avoidance. 23300829Sgrehan*/ 24300829Sgrehan 25300829Sgrehan 26300829Sgrehanchar * 27300829Sgrehanasctime(timeptr) 28300829Sgrehanconst struct tm * timeptr; 29300829Sgrehan{ 30300829Sgrehan static char result[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) + 31300829Sgrehan 3 + 2 + 1 + 1]; 32300829Sgrehan return(asctime_r(timeptr, result)); 33300829Sgrehan} 34300829Sgrehan 35300829Sgrehanchar * 36300829Sgrehanasctime_r(timeptr, result) 37300829Sgrehanconst struct tm * timeptr; 38300829Sgrehanchar *result; 39{ 40 static const char wday_name[][3] = { 41 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" 42 }; 43 static const char mon_name[][3] = { 44 "Jan", "Feb", "Mar", "Apr", "May", "Jun", 45 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" 46 }; 47 /* 48 ** Big enough for something such as 49 ** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n 50 ** (two three-character abbreviations, five strings denoting integers, 51 ** three explicit spaces, two explicit colons, a newline, 52 ** and a trailing ASCII nul). 53 */ 54 register const char * wn; 55 register const char * mn; 56 57 if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK) 58 wn = "???"; 59 else wn = wday_name[timeptr->tm_wday]; 60 if (timeptr->tm_mon < 0 || timeptr->tm_mon >= MONSPERYEAR) 61 mn = "???"; 62 else mn = mon_name[timeptr->tm_mon]; 63 /* 64 ** The X3J11-suggested format is 65 ** "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %d\n" 66 ** Since the .2 in 02.2d is ignored, we drop it. 67 */ 68 (void) sprintf(result, "%.3s %.3s%3d %02d:%02d:%02d %d\n", 69 wn, mn, 70 timeptr->tm_mday, timeptr->tm_hour, 71 timeptr->tm_min, timeptr->tm_sec, 72 TM_YEAR_BASE + timeptr->tm_year); 73 return result; 74} 75