|
1 /* |
|
2 ** This file is in the public domain, so clarified as of |
|
3 ** 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov). |
|
4 ** © Portions copyright (c) 2005-2006 Nokia Corporation. All rights reserved. |
|
5 */ |
|
6 |
|
7 #include <sys/cdefs.h> |
|
8 #ifndef lint |
|
9 #ifndef NOID |
|
10 static char elsieid[] __unused = "@(#)asctime.c 7.9"; |
|
11 #endif /* !defined NOID */ |
|
12 #endif /* !defined lint */ |
|
13 __FBSDID("$FreeBSD: src/lib/libc/stdtime/asctime.c,v 1.12 2004/06/14 10:31:52 stefanf Exp $"); |
|
14 |
|
15 /*LINTLIBRARY*/ |
|
16 |
|
17 #include "namespace.h" |
|
18 #include "private.h" |
|
19 #include "un-namespace.h" |
|
20 #include "tzfile.h" |
|
21 |
|
22 #ifdef __SYMBIAN32__ |
|
23 #if (defined(__SYMBIAN32__) && (defined(__WINSCW__) || defined(__WINS__))) |
|
24 #include "libc_wsd_defs.h" |
|
25 #endif |
|
26 |
|
27 #ifdef EMULATOR |
|
28 |
|
29 GET_STATIC_ARRAY_FROM_TLS(result, char) |
|
30 #define result (GET_WSD_VAR_NAME(result, s)()) |
|
31 #endif //EMULATOR |
|
32 #endif //__SYMBIAN32__ |
|
33 /* |
|
34 ** A la ISO/IEC 9945-1, ANSI/IEEE Std 1003.1, Second Edition, 1996-07-12. |
|
35 */ |
|
36 |
|
37 EXPORT_C |
|
38 char * |
|
39 asctime_r(timeptr, buf) |
|
40 const struct tm * timeptr; |
|
41 char * buf; |
|
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 const char * wn; |
|
51 const char * mn; |
|
52 |
|
53 #ifdef __SYMBIAN32__ |
|
54 if(timeptr==NULL) |
|
55 return NULL; |
|
56 #endif |
|
57 |
|
58 if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK) |
|
59 wn = "???"; |
|
60 else wn = wday_name[timeptr->tm_wday]; |
|
61 if (timeptr->tm_mon < 0 || timeptr->tm_mon >= MONSPERYEAR) |
|
62 mn = "???"; |
|
63 else mn = mon_name[timeptr->tm_mon]; |
|
64 /* |
|
65 ** The X3J11-suggested format is |
|
66 ** "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %d\n" |
|
67 ** Since the .2 in 02.2d is ignored, we drop it. |
|
68 */ |
|
69 (void) sprintf(buf, "%.3s %.3s%3d %02d:%02d:%02d %d\n", |
|
70 wn, mn, |
|
71 timeptr->tm_mday, timeptr->tm_hour, |
|
72 timeptr->tm_min, timeptr->tm_sec, |
|
73 TM_YEAR_BASE + timeptr->tm_year); |
|
74 return buf; |
|
75 } |
|
76 |
|
77 /* |
|
78 ** A la X3J11, with core dump avoidance. |
|
79 */ |
|
80 |
|
81 EXPORT_C |
|
82 char * |
|
83 asctime(timeptr) |
|
84 const struct tm * timeptr; |
|
85 { |
|
86 /* |
|
87 ** Big enough for something such as |
|
88 ** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n |
|
89 ** (two three-character abbreviations, five strings denoting integers, |
|
90 ** three explicit spaces, two explicit colons, a newline, |
|
91 ** and a trailing ASCII nul). |
|
92 */ |
|
93 #ifdef __SYMBIAN32__ |
|
94 #ifndef EMULATOR |
|
95 static char result[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) + |
|
96 3 + 2 + 1 + 1]; |
|
97 #endif //EMULATOR |
|
98 #else |
|
99 static char result[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) + |
|
100 3 + 2 + 1 + 1]; |
|
101 #endif // __SYMBIAN32__ |
|
102 |
|
103 return asctime_r(timeptr, result); |
|
104 } |
|
105 EXPORT_C |
|
106 wchar_t * |
|
107 wasctime(timeptr) |
|
108 const struct tm * timeptr; |
|
109 { |
|
110 static wchar_t wresult[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) + |
|
111 3 + 2 + 1 + 1]; |
|
112 /* |
|
113 ** Big enough for something such as |
|
114 ** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n |
|
115 ** (two three-character abbreviations, five strings denoting integers, |
|
116 ** three explicit spaces, two explicit colons, a newline, |
|
117 ** and a trailing ASCII nul). |
|
118 */ |
|
119 #ifdef __SYMBIAN32__ |
|
120 #ifndef EMULATOR |
|
121 static char result[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) + |
|
122 3 + 2 + 1 + 1]; |
|
123 #endif //EMULATOR |
|
124 #else |
|
125 static char result[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) + |
|
126 3 + 2 + 1 + 1]; |
|
127 #endif // __SYMBIAN32__ |
|
128 if (timeptr==NULL) |
|
129 return NULL; |
|
130 asctime_r(timeptr, result); |
|
131 mbstowcs(wresult, result, sizeof(wresult)/sizeof(wchar_t)); |
|
132 return wresult; |
|
133 } |