1 --- strftime.c.orig 2010-06-24 01:11:42.000000000 -0700
2 +++ strftime.c 2010-06-24 11:29:51.000000000 -0700
3 @@ -25,6 +25,8 @@ static const char elsieid[] = "@(#)strft
4 #endif /* !defined NOID */
5 #endif /* !defined lint */
7 +#include "xlocale_private.h"
12 @@ -35,18 +37,25 @@ static const char sccsid[] = "@(#)strfti
13 __FBSDID("$FreeBSD: src/lib/libc/stdtime/strftime.c,v 1.44 2009/06/09 09:02:58 delphij Exp $");
19 #include "un-namespace.h"
20 #include "timelocal.h"
22 +#if !BUILDING_VARIANT
23 static char * _add(const char *, char *, const char *);
24 -static char * _conv(int, const char *, char *, const char *);
25 -static char * _fmt(const char *, const struct tm *, char *, const char *,
27 -static char * _yconv(int, int, int, int, char *, const char *);
28 +static char * _conv(int, const char *, char *, const char *, locale_t);
29 +static char * _yconv(int, int, int, int, char *, const char *, locale_t);
32 +__private_extern__ char * _fmt(const char *, const struct tm *, char *, const char *,
33 + int *, struct lc_time_T *, locale_t);
35 extern char * tzname[];
36 +__private_extern__ long __darwin_altzone; /* DST timezone offset */
37 +#define altzone __darwin_altzone
38 +__private_extern__ long _st_get_timezone(void);
40 #ifndef YEAR_2000_NAME
41 #define YEAR_2000_NAME "CHECK_STRFTIME_FORMATS_FOR_TWO_DIGIT_YEARS"
42 @@ -62,6 +71,7 @@ extern char * tzname[];
46 +#ifndef BUILDING_VARIANT
47 static const char* fmt_padding[][4] = {
48 /* DEFAULT, LESS, SPACE, ZERO */
49 #define PAD_FMT_MONTHDAY 0
50 @@ -80,31 +90,36 @@ static const char* fmt_padding[][4] = {
51 #define PAD_FMT_YEAR 3
52 { "%04d", "%d", "%4d", "%04d" }
60 -strftime(char * __restrict s, size_t maxsize, const char * __restrict format,
61 - const struct tm * __restrict t)
62 +strftime_l(char * __restrict s, size_t maxsize, const char * __restrict format,
63 + const struct tm * __restrict t, locale_t loc)
68 + NORMALIZE_LOCALE(loc);
71 - p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn);
72 + p = _fmt(((format == NULL) ? "%c" : format), t, s, s + maxsize, &warn, __get_current_time_locale(loc), loc);
73 #ifndef NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU
74 if (warn != IN_NONE && getenv(YEAR_2000_NAME) != NULL) {
75 - (void) fprintf(stderr, "\n");
76 + (void) fputs("\n", stderr);
78 - (void) fprintf(stderr, "NULL strftime format ");
79 - else (void) fprintf(stderr, "strftime format \"%s\" ",
80 + (void) fputs("NULL strftime format ", stderr);
81 + else (void) fprintf_l(stderr, loc, "strftime format \"%s\" ",
83 - (void) fprintf(stderr, "yields only two digits of years in ");
84 + (void) fputs("yields only two digits of years in ", stderr);
86 - (void) fprintf(stderr, "some locales");
87 + (void) fputs("some locales", stderr);
88 else if (warn == IN_THIS)
89 - (void) fprintf(stderr, "the current locale");
90 - else (void) fprintf(stderr, "all locales");
91 - (void) fprintf(stderr, "\n");
92 + (void) fputs("the current locale", stderr);
93 + else (void) fputs("all locales", stderr);
94 + (void) fputs("\n", stderr);
96 #endif /* !defined NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU */
98 @@ -113,16 +128,25 @@ strftime(char * __restrict s, size_t max
103 -_fmt(format, t, pt, ptlim, warnp)
105 +strftime(char * __restrict s, size_t maxsize, const char * __restrict format,
106 + const struct tm * __restrict t)
108 + return strftime_l(s, maxsize, format, t, __current_locale());
111 +#ifndef BUILDING_VARIANT
112 +__private_extern__ char *
113 +_fmt(format, t, pt, ptlim, warnp, tptr, loc)
115 const struct tm * const t;
117 const char * const ptlim;
119 +struct lc_time_T * tptr;
122 int Ealternative, Oalternative, PadIndex;
123 - struct lc_time_T *tptr = __get_current_time_locale();
125 for ( ; *format; ++format) {
126 if (*format == '%') {
127 @@ -163,19 +187,19 @@ label:
130 ** %C used to do a...
131 - ** _fmt("%a %b %e %X %Y", t);
132 + ** _fmt("%a %b %e %X %Y", t, tptr, loc);
133 ** ...whereas now POSIX 1003.2 calls for
134 ** something completely different.
137 pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 0,
145 - pt = _fmt(tptr->c_fmt, t, pt, ptlim, &warn2);
146 + pt = _fmt(tptr->c_fmt, t, pt, ptlim, &warn2, tptr, loc);
150 @@ -183,11 +207,11 @@ label:
154 - pt = _fmt("%m/%d/%y", t, pt, ptlim, warnp);
155 + pt = _fmt("%m/%d/%y", t, pt, ptlim, warnp, tptr, loc);
158 pt = _conv(t->tm_mday, fmt_padding[PAD_FMT_DAYOFMONTH][PadIndex],
163 if (Ealternative || Oalternative)
164 @@ -213,29 +237,29 @@ label:
167 pt = _conv(t->tm_mday,
168 - fmt_padding[PAD_FMT_SDAYOFMONTH][PadIndex], pt, ptlim);
169 + fmt_padding[PAD_FMT_SDAYOFMONTH][PadIndex], pt, ptlim, loc);
172 - pt = _fmt("%Y-%m-%d", t, pt, ptlim, warnp);
173 + pt = _fmt("%Y-%m-%d", t, pt, ptlim, warnp, tptr, loc);
176 pt = _conv(t->tm_hour, fmt_padding[PAD_FMT_HMS][PadIndex],
181 pt = _conv((t->tm_hour % 12) ?
182 (t->tm_hour % 12) : 12,
183 - fmt_padding[PAD_FMT_HMS][PadIndex], pt, ptlim);
184 + fmt_padding[PAD_FMT_HMS][PadIndex], pt, ptlim, loc);
187 pt = _conv(t->tm_yday + 1,
188 - fmt_padding[PAD_FMT_DAYOFYEAR][PadIndex], pt, ptlim);
189 + fmt_padding[PAD_FMT_DAYOFYEAR][PadIndex], pt, ptlim, loc);
193 ** This used to be...
194 ** _conv(t->tm_hour % 12 ?
195 - ** t->tm_hour % 12 : 12, 2, ' ');
196 + ** t->tm_hour % 12 : 12, 2, ' ', loc);
197 ** ...and has been changed to the below to
198 ** match SunOS 4.1.1 and Arnold Robbins'
199 ** strftime version 3.0. That is, "%k" and
200 @@ -243,7 +267,7 @@ label:
203 pt = _conv(t->tm_hour, fmt_padding[PAD_FMT_SHMS][PadIndex],
209 @@ -265,15 +289,15 @@ label:
211 pt = _conv((t->tm_hour % 12) ?
212 (t->tm_hour % 12) : 12,
213 - fmt_padding[PAD_FMT_SHMS][PadIndex], pt, ptlim);
214 + fmt_padding[PAD_FMT_SHMS][PadIndex], pt, ptlim, loc);
217 pt = _conv(t->tm_min, fmt_padding[PAD_FMT_HMS][PadIndex],
222 pt = _conv(t->tm_mon + 1,
223 - fmt_padding[PAD_FMT_MONTH][PadIndex], pt, ptlim);
224 + fmt_padding[PAD_FMT_MONTH][PadIndex], pt, ptlim, loc);
227 pt = _add("\n", pt, ptlim);
228 @@ -285,15 +309,15 @@ label:
232 - pt = _fmt("%H:%M", t, pt, ptlim, warnp);
233 + pt = _fmt("%H:%M", t, pt, ptlim, warnp, tptr, loc);
236 pt = _fmt(tptr->ampm_fmt, t, pt, ptlim,
241 pt = _conv(t->tm_sec, fmt_padding[PAD_FMT_HMS][PadIndex],
247 @@ -305,15 +329,15 @@ label:
250 if (TYPE_SIGNED(time_t))
251 - (void) sprintf(buf, "%ld",
252 + (void) sprintf_l(buf, loc, "%ld",
254 - else (void) sprintf(buf, "%lu",
255 + else (void) sprintf_l(buf, loc, "%lu",
256 (unsigned long) mkt);
257 pt = _add(buf, pt, ptlim);
261 - pt = _fmt("%H:%M:%S", t, pt, ptlim, warnp);
262 + pt = _fmt("%H:%M:%S", t, pt, ptlim, warnp, tptr, loc);
265 pt = _add("\t", pt, ptlim);
266 @@ -321,7 +345,7 @@ label:
268 pt = _conv((t->tm_yday + DAYSPERWEEK -
269 t->tm_wday) / DAYSPERWEEK,
270 - fmt_padding[PAD_FMT_WEEKOFYEAR][PadIndex], pt, ptlim);
271 + fmt_padding[PAD_FMT_WEEKOFYEAR][PadIndex], pt, ptlim, loc);
275 @@ -332,7 +356,7 @@ label:
277 pt = _conv((t->tm_wday == 0) ?
278 DAYSPERWEEK : t->tm_wday,
280 + "%d", pt, ptlim, loc);
282 case 'V': /* ISO 8601 week number */
283 case 'G': /* ISO 8601 year (four digits) */
284 @@ -413,13 +437,13 @@ label:
285 #endif /* defined XPG4_1994_04_09 */
287 pt = _conv(w, fmt_padding[PAD_FMT_WEEKOFYEAR][PadIndex],
290 else if (*format == 'g') {
292 pt = _yconv(year, base, 0, 1,
295 } else pt = _yconv(year, base, 1, 1,
301 @@ -428,26 +452,26 @@ label:
302 ** "date as dd-bbb-YYYY"
305 - pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp);
306 + pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp, tptr, loc);
309 pt = _conv((t->tm_yday + DAYSPERWEEK -
312 (DAYSPERWEEK - 1))) / DAYSPERWEEK,
313 - fmt_padding[PAD_FMT_WEEKOFYEAR][PadIndex], pt, ptlim);
314 + fmt_padding[PAD_FMT_WEEKOFYEAR][PadIndex], pt, ptlim, loc);
317 - pt = _conv(t->tm_wday, "%d", pt, ptlim);
318 + pt = _conv(t->tm_wday, "%d", pt, ptlim, loc);
321 - pt = _fmt(tptr->X_fmt, t, pt, ptlim, warnp);
322 + pt = _fmt(tptr->X_fmt, t, pt, ptlim, warnp, tptr, loc);
328 - pt = _fmt(tptr->x_fmt, t, pt, ptlim, &warn2);
329 + pt = _fmt(tptr->x_fmt, t, pt, ptlim, &warn2, tptr, loc);
333 @@ -457,11 +481,11 @@ label:
336 pt = _yconv(t->tm_year, TM_YEAR_BASE, 0, 1,
341 pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 1,
347 @@ -485,9 +509,9 @@ label:
352 +#if defined(TM_GMTOFF) && !__DARWIN_UNIX03
354 -#else /* !defined TM_GMTOFF */
355 +#else /* !defined TM_GMTOFF || __DARWIN_UNIX03 */
357 ** C99 says that the UTC offset must
358 ** be computed by looking only at
359 @@ -509,7 +533,7 @@ label:
361 if (t->tm_isdst == 0)
364 + diff = -_st_get_timezone();
365 #else /* !defined USG_COMPAT */
367 #endif /* !defined USG_COMPAT */
368 @@ -519,7 +543,7 @@ label:
369 #else /* !defined ALTZONE */
371 #endif /* !defined ALTZONE */
372 -#endif /* !defined TM_GMTOFF */
373 +#endif /* !defined TM_GMTOFF || __DARWIN_UNIX03 */
377 @@ -529,12 +553,12 @@ label:
378 diff = (diff / MINSPERHOUR) * 100 +
379 (diff % MINSPERHOUR);
381 - fmt_padding[PAD_FMT_YEAR][PadIndex], pt, ptlim);
382 + fmt_padding[PAD_FMT_YEAR][PadIndex], pt, ptlim, loc);
386 pt = _fmt(tptr->date_fmt, t, pt, ptlim,
391 if (PadIndex != PAD_DEFAULT)
392 @@ -569,15 +593,16 @@ label:
396 -_conv(n, format, pt, ptlim)
397 +_conv(n, format, pt, ptlim, loc)
399 const char * const format;
401 const char * const ptlim;
404 char buf[INT_STRLEN_MAXIMUM(int) + 1];
406 - (void) sprintf(buf, format, n);
407 + (void) sprintf_l(buf, loc, format, n);
408 return _add(buf, pt, ptlim);
411 @@ -601,13 +626,14 @@ const char * const ptlim;
415 -_yconv(a, b, convert_top, convert_yy, pt, ptlim)
416 +_yconv(a, b, convert_top, convert_yy, pt, ptlim, loc)
419 const int convert_top;
420 const int convert_yy;
422 const char * const ptlim;
427 @@ -626,9 +652,10 @@ const char * const ptlim;
429 if (lead == 0 && trail < 0)
430 pt = _add("-0", pt, ptlim);
431 - else pt = _conv(lead, "%02d", pt, ptlim);
432 + else pt = _conv(lead, "%02d", pt, ptlim, loc);
435 - pt = _conv(((trail < 0) ? -trail : trail), "%02d", pt, ptlim);
436 + pt = _conv(((trail < 0) ? -trail : trail), "%02d", pt, ptlim, loc);
439 +#endif /* !BUILDING_VARIANT */