X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Ftime%2Fstrftime.c;h=3f0ec3e3345df9c1c0d3c5e1df78295932b3b65e;hb=7406fdf5a18b37330de108abb0106f44ebdae2c6;hp=576870589c1a71edeb0fc612e15b22cd35366a8c;hpb=aea79190326cf81d6c8ec81ab163137591c6dac8;p=musl diff --git a/src/time/strftime.c b/src/time/strftime.c index 57687058..3f0ec3e3 100644 --- a/src/time/strftime.c +++ b/src/time/strftime.c @@ -1,13 +1,14 @@ #include #include #include +#include #include #include -#include "__time.h" +#include "libc.h" // FIXME: integer overflows -const char *__langinfo(nl_item); +const char *__nl_langinfo_l(nl_item, locale_t); static int is_leap(int y) { @@ -43,14 +44,18 @@ static int week_num(const struct tm *tm) return val; } -size_t strftime(char *restrict s, size_t n, const char *restrict f, const struct tm *restrict tm) +size_t __strftime_l(char *restrict s, size_t n, const char *restrict f, const struct tm *restrict tm, locale_t loc) { nl_item item; int val; const char *fmt; size_t l; for (l=0; *f && ltm_isdst < 0) continue; - val = -__timezone - (tm->tm_isdst ? __dst_offset : 0); + val = -tm->__tm_gmtoff; l += snprintf(s+l, n-l, "%+.2d%.2d", val/3600, abs(val%3600)/60); continue; case 'Z': - if (tm->tm_isdst < 0 || !__tzname[0] || !__tzname[0][0]) - continue; - l += snprintf(s+l, n-l, "%s", __tzname[!!tm->tm_isdst]); + l += snprintf(s+l, n-l, "%s", tm->__tm_zone); continue; default: return 0; } - } -literal: - s[l++] = *f; - continue; number: l += snprintf(s+l, n-l, fmt, val); continue; nl_strcat: - l += snprintf(s+l, n-l, "%s", __langinfo(item)); + l += snprintf(s+l, n-l, "%s", __nl_langinfo_l(item, loc)); continue; nl_strftime: - fmt = __langinfo(item); + fmt = __nl_langinfo_l(item, loc); recu_strftime: - l += strftime(s+l, n-l, fmt, tm); + l += __strftime_l(s+l, n-l, fmt, tm, loc); } if (l >= n) return 0; s[l] = 0; return l; } + +size_t strftime(char *restrict s, size_t n, const char *restrict f, const struct tm *restrict tm) +{ + return __strftime_l(s, n, f, tm, 0); +} + +weak_alias(__strftime_l, strftime_l);