|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <sys/cdefs.h> |
|
20 #ifndef lint |
|
21 #ifndef NOID |
|
22 static char elsieid[] __unused = "@(#)asctime.c 7.9"; |
|
23 #endif /* !defined NOID */ |
|
24 #endif /* !defined lint */ |
|
25 __FBSDID("$FreeBSD: src/lib/libc/stdtime/asctime.c,v 1.12 2004/06/14 10:31:52 stefanf Exp $"); |
|
26 |
|
27 /*LINTLIBRARY*/ |
|
28 |
|
29 #include "namespace.h" |
|
30 #include "private.h" |
|
31 #include "un-namespace.h" |
|
32 #include "tzfile.h" |
|
33 |
|
34 #ifdef __SYMBIAN32__ |
|
35 #if (defined(__SYMBIAN32__) && (defined(__WINSCW__) || defined(__WINS__))) |
|
36 #include "libc_wsd_defs.h" |
|
37 #endif |
|
38 |
|
39 #ifdef EMULATOR |
|
40 |
|
41 GET_STATIC_ARRAY_FROM_TLS(result, char) |
|
42 #define result (GET_WSD_VAR_NAME(result, s)()) |
|
43 #endif //EMULATOR |
|
44 #endif //__SYMBIAN32__ |
|
45 /* |
|
46 ** A la ISO/IEC 9945-1, ANSI/IEEE Std 1003.1, Second Edition, 1996-07-12. |
|
47 */ |
|
48 |
|
49 EXPORT_C |
|
50 char * |
|
51 asctime_r(timeptr, buf) |
|
52 const struct tm * timeptr; |
|
53 char * buf; |
|
54 { |
|
55 static const char wday_name[][3] = { |
|
56 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" |
|
57 }; |
|
58 static const char mon_name[][3] = { |
|
59 "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
|
60 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" |
|
61 }; |
|
62 const char * wn; |
|
63 const char * mn; |
|
64 |
|
65 #ifdef __SYMBIAN32__ |
|
66 if(timeptr==NULL) |
|
67 return NULL; |
|
68 #endif |
|
69 |
|
70 if (timeptr->tm_wday < 0 || timeptr->tm_wday >= DAYSPERWEEK) |
|
71 wn = "???"; |
|
72 else wn = wday_name[timeptr->tm_wday]; |
|
73 if (timeptr->tm_mon < 0 || timeptr->tm_mon >= MONSPERYEAR) |
|
74 mn = "???"; |
|
75 else mn = mon_name[timeptr->tm_mon]; |
|
76 /* |
|
77 ** The X3J11-suggested format is |
|
78 ** "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %d\n" |
|
79 ** Since the .2 in 02.2d is ignored, we drop it. |
|
80 */ |
|
81 (void) sprintf(buf, "%.3s %.3s%3d %02d:%02d:%02d %d\n", |
|
82 wn, mn, |
|
83 timeptr->tm_mday, timeptr->tm_hour, |
|
84 timeptr->tm_min, timeptr->tm_sec, |
|
85 TM_YEAR_BASE + timeptr->tm_year); |
|
86 return buf; |
|
87 } |
|
88 |
|
89 /* |
|
90 ** A la X3J11, with core dump avoidance. |
|
91 */ |
|
92 |
|
93 EXPORT_C |
|
94 char * |
|
95 asctime(timeptr) |
|
96 const struct tm * timeptr; |
|
97 { |
|
98 /* |
|
99 ** Big enough for something such as |
|
100 ** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n |
|
101 ** (two three-character abbreviations, five strings denoting integers, |
|
102 ** three explicit spaces, two explicit colons, a newline, |
|
103 ** and a trailing ASCII nul). |
|
104 */ |
|
105 #ifdef __SYMBIAN32__ |
|
106 #ifndef EMULATOR |
|
107 static char result[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) + |
|
108 3 + 2 + 1 + 1]; |
|
109 #endif //EMULATOR |
|
110 #else |
|
111 static char result[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) + |
|
112 3 + 2 + 1 + 1]; |
|
113 #endif // __SYMBIAN32__ |
|
114 |
|
115 return asctime_r(timeptr, result); |
|
116 } |
|
117 EXPORT_C |
|
118 wchar_t * |
|
119 wasctime(timeptr) |
|
120 const struct tm * timeptr; |
|
121 { |
|
122 static wchar_t wresult[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) + |
|
123 3 + 2 + 1 + 1]; |
|
124 /* |
|
125 ** Big enough for something such as |
|
126 ** ??? ???-2147483648 -2147483648:-2147483648:-2147483648 -2147483648\n |
|
127 ** (two three-character abbreviations, five strings denoting integers, |
|
128 ** three explicit spaces, two explicit colons, a newline, |
|
129 ** and a trailing ASCII nul). |
|
130 */ |
|
131 #ifdef __SYMBIAN32__ |
|
132 #ifndef EMULATOR |
|
133 static char result[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) + |
|
134 3 + 2 + 1 + 1]; |
|
135 #endif //EMULATOR |
|
136 #else |
|
137 static char result[3 * 2 + 5 * INT_STRLEN_MAXIMUM(int) + |
|
138 3 + 2 + 1 + 1]; |
|
139 #endif // __SYMBIAN32__ |
|
140 if (timeptr==NULL) |
|
141 return NULL; |
|
142 asctime_r(timeptr, result); |
|
143 mbstowcs(wresult, result, sizeof(wresult)/sizeof(wchar_t)); |
|
144 return wresult; |
|
145 } |