1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
24 * strftime implementation
27 #define strftime ______strftime
37 #undef _lib_strftime /* we can pass X/Open */
45 #if defined(__EXPORT__)
46 #define extern __EXPORT__
50 strftime(char* buf
, size_t len
, const char* format
, const struct tm
* tm
)
56 memset(&tl
, 0, sizeof(tl
));
59 * nl_langinfo() may call strftime() with bogus tm except for
60 * one value -- what a way to go
63 if (tm
->tm_sec
< 0 || tm
->tm_sec
> 60 ||
64 tm
->tm_min
< 0 || tm
->tm_min
> 59 ||
65 tm
->tm_hour
< 0 || tm
->tm_hour
> 23 ||
66 tm
->tm_wday
< 0 || tm
->tm_wday
> 6 ||
67 tm
->tm_mday
< 1 || tm
->tm_mday
> 31 ||
68 tm
->tm_mon
< 0 || tm
->tm_mon
> 11 ||
69 tm
->tm_year
< 0 || tm
->tm_year
> (2138 - 1900))
71 if (tm
->tm_sec
>= 0 && tm
->tm_sec
<= 60)
72 tl
.tm_sec
= tm
->tm_sec
;
73 if (tm
->tm_min
>= 0 && tm
->tm_min
<= 59)
74 tl
.tm_min
= tm
->tm_min
;
75 if (tm
->tm_hour
>= 0 && tm
->tm_hour
<= 23)
76 tl
.tm_hour
= tm
->tm_hour
;
77 if (tm
->tm_wday
>= 0 && tm
->tm_wday
<= 6)
78 tl
.tm_wday
= tm
->tm_wday
;
79 if (tm
->tm_mday
>= 0 && tm
->tm_mday
<= 31)
80 tl
.tm_mday
= tm
->tm_mday
;
81 if (tm
->tm_mon
>= 0 && tm
->tm_mon
<= 11)
82 tl
.tm_mon
= tm
->tm_mon
;
83 if (tm
->tm_year
>= 0 && tm
->tm_year
<= (2138 - 1900))
84 tl
.tm_year
= tm
->tm_year
;
88 tl
.tm_sec
= tm
->tm_sec
;
89 tl
.tm_min
= tm
->tm_min
;
90 tl
.tm_hour
= tm
->tm_hour
;
91 tl
.tm_mday
= tm
->tm_mday
;
92 tl
.tm_mon
= tm
->tm_mon
;
93 tl
.tm_year
= tm
->tm_year
;
94 tl
.tm_wday
= tm
->tm_wday
;
95 tl
.tm_yday
= tm
->tm_yday
;
96 tl
.tm_isdst
= tm
->tm_isdst
;
98 t
= tmtime(&tl
, TM_LOCALZONE
);
99 if (!(s
= tmfmt(buf
, len
, format
, &t
)))