2 * code found at: http://www.uni-paderborn.de/info/solaris_porting_faq
5 * Copyright (c) 1994 Powerdog Industries. All rights reserved.
7 * Redistribution and use in source and binary forms, without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgement:
18 * This product includes software developed by Powerdog Industries.
19 * 4. The name of Powerdog Industries may not be used to endorse or
20 * promote products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY POWERDOG INDUSTRIES ``AS IS'' AND ANY
24 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE POWERDOG INDUSTRIES BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
33 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 /* A few changes by Steve Dekorte:
37 * - renamed function and moved En_US into function
40 #include "PortableStrptime.h"
42 /*#ifdef IO_NEEDS_STRPTIME*/
49 #define asizeof(a) (sizeof (a) / sizeof ((a)[0]))
53 char *abbrev_month_names
[12];
54 char *month_names
[12];
55 char *abbrev_weekday_names
[7];
56 char *weekday_names
[7];
67 extern int strncasecmp();
70 #if defined(_MSC_VER) && !defined(__SYMBIAN32__)
71 #define strcasecmp _stricmp
72 #define strncasecmp _strnicmp
75 int readndigits(char **const buf
, const size_t count
)
80 for (i
= 0; i
< count
; i
++, (*buf
)++) {
81 const char digit
= **buf
;
82 if (digit
== 0 || !isdigit(digit
)) {
86 result
+= digit
- '0';
92 // TODO rename function when I understand what this function does.
93 void somethingToDoWithSpaces(const char *const buf
, char **const ptr
)
95 if (*buf
!= 0 && isspace((int)*buf
)) {
96 while (**ptr
!= 0 && !isspace((int)**ptr
)) {
102 char *io_strptime(char *buf
, char *fmt
, struct tm
*tm
)
104 struct dtconv En_US
= {
105 { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
106 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" },
107 { "January", "February", "March", "April",
108 "May", "June", "July", "August",
109 "September", "October", "November", "December" },
110 { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" },
111 { "Sunday", "Monday", "Tuesday", "Wednesday",
112 "Thursday", "Friday", "Saturday" },
136 while (*buf
!= 0 && isspace((int)*buf
))
138 else if (c
!= *buf
++)
154 buf
= io_strptime(buf
, En_US
.ldate_format
, tm
);
160 buf
= io_strptime(buf
, "%x %X", tm
);
166 buf
= io_strptime(buf
, "%m/%d/%y", tm
);
172 buf
= io_strptime(buf
, "%H:%M", tm
);
178 buf
= io_strptime(buf
, "%I:%M:%S %p", tm
);
184 buf
= io_strptime(buf
, "%H:%M:%S", tm
);
190 buf
= io_strptime(buf
, En_US
.time_format
, tm
);
196 buf
= io_strptime(buf
, En_US
.sdate_format
, tm
);
202 if (*buf
== 0 || isspace((int)*buf
))
205 i
= readndigits(&buf
, 3);
206 if (i
< 0 || i
> 366)
213 if (*buf
== 0 || isspace((int)*buf
))
216 i
= readndigits(&buf
, 2);
222 somethingToDoWithSpaces(buf
, &ptr
);
226 if (*buf
== 0 || isspace((int)*buf
))
229 i
= readndigits(&buf
, 2);
230 if (i
< 0 || i
> 60) // Earlier 61 was also allowed.
235 somethingToDoWithSpaces(buf
, &ptr
);
240 if (!isdigit((int)*buf
))
243 i
= readndigits(&buf
, 2);
249 somethingToDoWithSpaces(buf
, &ptr
);
254 if (!isdigit((int)*buf
))
257 i
= readndigits(&buf
, 2);
263 somethingToDoWithSpaces(buf
, &ptr
);
268 if (!isdigit((int)*buf
))
271 i
= readndigits(&buf
, 2);
277 somethingToDoWithSpaces(buf
, &ptr
);
281 if (!isdigit((int)*buf
))
284 i
= readndigits(&buf
, 2);
290 somethingToDoWithSpaces(buf
, &ptr
);
294 if (*buf
== 0 || isspace((int)*buf
))
297 if (!isdigit((int)*buf
))
300 i
= readndigits(&buf
, 4);
301 if (i
< 0 || i
> 9999)
304 tm
->tm_year
= i
- 1900;
306 somethingToDoWithSpaces(buf
, &ptr
);
310 if (*buf
== 0 || isspace((int)*buf
))
313 if (!isdigit((int)*buf
))
316 i
= readndigits(&buf
, 2);
322 somethingToDoWithSpaces(buf
, &ptr
);
327 len
= strlen(En_US
.am_string
);
328 if (strncasecmp(buf
, En_US
.am_string
, len
) == 0) {
329 if (tm
->tm_hour
> 12)
331 if (tm
->tm_hour
== 12)
337 len
= strlen(En_US
.pm_string
);
338 if (strncasecmp(buf
, En_US
.pm_string
, len
) == 0) {
339 if (tm
->tm_hour
> 12)
341 if (tm
->tm_hour
!= 12)
351 for (i
= 0; i
< (int)asizeof(En_US
.weekday_names
); i
++) {
352 len
= strlen(En_US
.weekday_names
[i
]);
354 En_US
.weekday_names
[i
],
358 len
= strlen(En_US
.abbrev_weekday_names
[i
]);
360 En_US
.abbrev_weekday_names
[i
],
364 if (i
== asizeof(En_US
.weekday_names
))
374 for (i
= 0; i
< (int)asizeof(En_US
.month_names
); i
++) {
375 len
= strlen(En_US
.month_names
[i
]);
377 En_US
.month_names
[i
],
381 len
= strlen(En_US
.abbrev_month_names
[i
]);
383 En_US
.abbrev_month_names
[i
],
387 if (i
== asizeof(En_US
.month_names
))