diff options
author | pfg <pfg@FreeBSD.org> | 2014-08-03 18:31:52 +0000 |
---|---|---|
committer | pfg <pfg@FreeBSD.org> | 2014-08-03 18:31:52 +0000 |
commit | 4edbce8b348a54d29189a62a9b6e7b2212efa95c (patch) | |
tree | 0505f87453eb2afb7c9b1d05265ced81fcf7db7f /lib/libc/stdtime | |
parent | 5c8726d1b258dd69e1f906f463c2bcc65c1b64a5 (diff) | |
download | FreeBSD-src-4edbce8b348a54d29189a62a9b6e7b2212efa95c.zip FreeBSD-src-4edbce8b348a54d29189a62a9b6e7b2212efa95c.tar.gz |
MFC r269124:
strftime() xlocale cleanups.
Replace fprintf_l with fputs when output is unformatted.
Use locale_t in _conv() since it was using sprintf (now sprintf_l)
Use locale_t on _yconv() since it calls _conv()
Obtained from: Apple Inc. (Libc 997.90.3)
CR: D482
Reviewed by: theraven
Diffstat (limited to 'lib/libc/stdtime')
-rw-r--r-- | lib/libc/stdtime/strftime.c | 83 |
1 files changed, 46 insertions, 37 deletions
diff --git a/lib/libc/stdtime/strftime.c b/lib/libc/stdtime/strftime.c index 178dd0f..8981011 100644 --- a/lib/libc/stdtime/strftime.c +++ b/lib/libc/stdtime/strftime.c @@ -46,10 +46,10 @@ __FBSDID("$FreeBSD$"); #include "timelocal.h" static char * _add(const char *, char *, const char *); -static char * _conv(int, const char *, char *, const char *); +static char * _conv(int, const char *, char *, const char *, locale_t); static char * _fmt(const char *, const struct tm *, char *, const char *, int *, locale_t); -static char * _yconv(int, int, int, int, char *, const char *); +static char * _yconv(int, int, int, int, char *, const char *, locale_t); extern char * tzname[]; @@ -101,16 +101,16 @@ strftime_l(char * __restrict s, size_t maxsize, const char * __restrict format, if (warn != IN_NONE && getenv(YEAR_2000_NAME) != NULL) { (void) fprintf_l(stderr, loc, "\n"); if (format == NULL) - (void) fprintf_l(stderr, loc, "NULL strftime format "); + (void) fputs("NULL strftime format ", stderr); else (void) fprintf_l(stderr, loc, "strftime format \"%s\" ", format); - (void) fprintf_l(stderr, loc, "yields only two digits of years in "); + (void) fputs("yields only two digits of years in ", stderr); if (warn == IN_SOME) - (void) fprintf_l(stderr, loc, "some locales"); + (void) fputs("some locales", stderr); else if (warn == IN_THIS) - (void) fprintf_l(stderr, loc, "the current locale"); - else (void) fprintf_l(stderr, loc, "all locales"); - (void) fprintf_l(stderr, loc, "\n"); + (void) fputs("the current locale", stderr); + else (void) fputs("all locales", stderr); + (void) fputs("\n", stderr); } #endif /* !defined NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU */ if (p == s + maxsize) @@ -183,7 +183,7 @@ label: * (ado, 1993-05-24) */ pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 0, - pt, ptlim); + pt, ptlim, loc); continue; case 'c': { @@ -200,8 +200,9 @@ label: pt = _fmt("%m/%d/%y", t, pt, ptlim, warnp, loc); continue; case 'd': - pt = _conv(t->tm_mday, fmt_padding[PAD_FMT_DAYOFMONTH][PadIndex], - pt, ptlim); + pt = _conv(t->tm_mday, + fmt_padding[PAD_FMT_DAYOFMONTH][PadIndex], + pt, ptlim, loc); continue; case 'E': if (Ealternative || Oalternative) @@ -227,24 +228,26 @@ label: goto label; case 'e': pt = _conv(t->tm_mday, - fmt_padding[PAD_FMT_SDAYOFMONTH][PadIndex], pt, ptlim); + fmt_padding[PAD_FMT_SDAYOFMONTH][PadIndex], + pt, ptlim, loc); continue; case 'F': pt = _fmt("%Y-%m-%d", t, pt, ptlim, warnp, loc); continue; case 'H': pt = _conv(t->tm_hour, fmt_padding[PAD_FMT_HMS][PadIndex], - pt, ptlim); + pt, ptlim, loc); continue; case 'I': pt = _conv((t->tm_hour % 12) ? (t->tm_hour % 12) : 12, fmt_padding[PAD_FMT_HMS][PadIndex], - pt, ptlim); + pt, ptlim, loc); continue; case 'j': pt = _conv(t->tm_yday + 1, - fmt_padding[PAD_FMT_DAYOFYEAR][PadIndex], pt, ptlim); + fmt_padding[PAD_FMT_DAYOFYEAR][PadIndex], + pt, ptlim, loc); continue; case 'k': /* @@ -258,7 +261,7 @@ label: * (ado, 1993-05-24) */ pt = _conv(t->tm_hour, fmt_padding[PAD_FMT_SHMS][PadIndex], - pt, ptlim); + pt, ptlim, loc); continue; #ifdef KITCHEN_SINK case 'K': @@ -281,16 +284,16 @@ label: pt = _conv((t->tm_hour % 12) ? (t->tm_hour % 12) : 12, fmt_padding[PAD_FMT_SHMS][PadIndex], - pt, ptlim); + pt, ptlim, loc); continue; case 'M': pt = _conv(t->tm_min, fmt_padding[PAD_FMT_HMS][PadIndex], - pt, ptlim); + pt, ptlim, loc); continue; case 'm': pt = _conv(t->tm_mon + 1, fmt_padding[PAD_FMT_MONTH][PadIndex], - pt, ptlim); + pt, ptlim, loc); continue; case 'n': pt = _add("\n", pt, ptlim); @@ -309,7 +312,7 @@ label: continue; case 'S': pt = _conv(t->tm_sec, fmt_padding[PAD_FMT_HMS][PadIndex], - pt, ptlim); + pt, ptlim, loc); continue; case 's': { @@ -321,9 +324,9 @@ label: tm = *t; mkt = mktime(&tm); if (TYPE_SIGNED(time_t)) - (void) sprintf(buf, "%ld", + (void) sprintf_l(buf, loc, "%ld", (long) mkt); - else (void) sprintf(buf, "%lu", + else (void) sprintf_l(buf, loc, "%lu", (unsigned long) mkt); pt = _add(buf, pt, ptlim); } @@ -337,7 +340,8 @@ label: case 'U': pt = _conv((t->tm_yday + DAYSPERWEEK - t->tm_wday) / DAYSPERWEEK, - fmt_padding[PAD_FMT_WEEKOFYEAR][PadIndex], pt, ptlim); + fmt_padding[PAD_FMT_WEEKOFYEAR][PadIndex], + pt, ptlim, loc); continue; case 'u': /* @@ -348,7 +352,7 @@ label: */ pt = _conv((t->tm_wday == 0) ? DAYSPERWEEK : t->tm_wday, - "%d", pt, ptlim); + "%d", pt, ptlim, loc); continue; case 'V': /* ISO 8601 week number */ case 'G': /* ISO 8601 year (four digits) */ @@ -429,13 +433,13 @@ label: #endif /* defined XPG4_1994_04_09 */ if (*format == 'V') pt = _conv(w, fmt_padding[PAD_FMT_WEEKOFYEAR][PadIndex], - pt, ptlim); + pt, ptlim, loc); else if (*format == 'g') { *warnp = IN_ALL; pt = _yconv(year, base, 0, 1, - pt, ptlim); + pt, ptlim, loc); } else pt = _yconv(year, base, 1, 1, - pt, ptlim); + pt, ptlim, loc); } continue; case 'v': @@ -451,10 +455,11 @@ label: (t->tm_wday ? (t->tm_wday - 1) : (DAYSPERWEEK - 1))) / DAYSPERWEEK, - fmt_padding[PAD_FMT_WEEKOFYEAR][PadIndex], pt, ptlim); + fmt_padding[PAD_FMT_WEEKOFYEAR][PadIndex], + pt, ptlim, loc); continue; case 'w': - pt = _conv(t->tm_wday, "%d", pt, ptlim); + pt = _conv(t->tm_wday, "%d", pt, ptlim, loc); continue; case 'X': pt = _fmt(tptr->X_fmt, t, pt, ptlim, warnp, loc); @@ -473,11 +478,11 @@ label: case 'y': *warnp = IN_ALL; pt = _yconv(t->tm_year, TM_YEAR_BASE, 0, 1, - pt, ptlim); + pt, ptlim, loc); continue; case 'Y': pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 1, - pt, ptlim); + pt, ptlim, loc); continue; case 'Z': #ifdef TM_ZONE @@ -546,7 +551,8 @@ label: diff = (diff / MINSPERHOUR) * 100 + (diff % MINSPERHOUR); pt = _conv(diff, - fmt_padding[PAD_FMT_YEAR][PadIndex], pt, ptlim); + fmt_padding[PAD_FMT_YEAR][PadIndex], + pt, ptlim, loc); } continue; case '+': @@ -586,15 +592,16 @@ label: } static char * -_conv(n, format, pt, ptlim) +_conv(n, format, pt, ptlim, loc) const int n; const char * const format; char * const pt; const char * const ptlim; +locale_t loc; { char buf[INT_STRLEN_MAXIMUM(int) + 1]; - (void) sprintf(buf, format, n); + (void) sprintf_l(buf, loc, format, n); return _add(buf, pt, ptlim); } @@ -618,13 +625,14 @@ const char * const ptlim; */ static char * -_yconv(a, b, convert_top, convert_yy, pt, ptlim) +_yconv(a, b, convert_top, convert_yy, pt, ptlim, loc) const int a; const int b; const int convert_top; const int convert_yy; char * pt; const char * const ptlim; +locale_t loc; { register int lead; register int trail; @@ -643,9 +651,10 @@ const char * const ptlim; if (convert_top) { if (lead == 0 && trail < 0) pt = _add("-0", pt, ptlim); - else pt = _conv(lead, "%02d", pt, ptlim); + else pt = _conv(lead, "%02d", pt, ptlim, loc); } if (convert_yy) - pt = _conv(((trail < 0) ? -trail : trail), "%02d", pt, ptlim); + pt = _conv(((trail < 0) ? -trail : trail), "%02d", pt, + ptlim, loc); return (pt); } |