X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Ftime%2Fwcsftime.c;h=8d2a2ebc3fa18bf34935b0adf6a40a31e9a88e78;hb=7cbb6f70c8fe711644ec0dbede1973cc6641a283;hp=72af913775fa7084f686b4ebd456fe7902a1da5b;hpb=fc48ceee773e851d8be675f25be4f476646aa99e;p=musl diff --git a/src/time/wcsftime.c b/src/time/wcsftime.c index 72af9137..8d2a2ebc 100644 --- a/src/time/wcsftime.c +++ b/src/time/wcsftime.c @@ -1,6 +1,5 @@ #include #include -#include #include #include "libc.h" @@ -16,7 +15,7 @@ size_t __wcsftime_l(wchar_t *restrict s, size_t n, const wchar_t *restrict f, co const wchar_t *t; int plus; unsigned long width; - for (l=0; l+1= n-l) return 0; } else { width = 0; } f = p; if (*f == 'E' || *f == 'O') f++; t_mb = __strftime_fmt_1(&buf, &k, *f, tm, loc); - if (!t_mb) return 0; + if (!t_mb) break; k = mbstowcs(wbuf, t_mb, sizeof wbuf / sizeof *wbuf); if (k == (size_t)-1) return 0; t = wbuf; @@ -50,14 +48,17 @@ size_t __wcsftime_l(wchar_t *restrict s, size_t n, const wchar_t *restrict f, co s[l++] = '-'; else width++; - if (width >= n-l) return 0; - for (; width > k; width--) + for (; width > k && l < n; width--) s[l++] = '0'; } - if (k >= n-l) return 0; + if (k >= n-l) k = n-l; wmemcpy(s+l, t, k); l += k; } + if (n) { + if (l==n) l=n-1; + s[l] = 0; + } return 0; }