| OLD | NEW |
| 1 #include <wchar.h> | 1 #include <wchar.h> |
| 2 #include <time.h> | 2 #include <time.h> |
| 3 #include <locale.h> | 3 #include <locale.h> |
| 4 #include "locale_impl.h" | 4 #include "locale_impl.h" |
| 5 #include "libc.h" | 5 #include "libc.h" |
| 6 | 6 |
| 7 const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm *
tm, locale_t loc); | 7 const char* __strftime_fmt_1(char (*s)[100], |
| 8 size_t* l, |
| 9 int f, |
| 10 const struct tm* tm, |
| 11 locale_t loc); |
| 8 | 12 |
| 9 size_t __wcsftime_l(wchar_t *restrict s, size_t n, const wchar_t *restrict f, co
nst struct tm *restrict tm, locale_t loc) | 13 size_t __wcsftime_l(wchar_t* restrict s, |
| 10 { | 14 size_t n, |
| 11 » size_t l, k; | 15 const wchar_t* restrict f, |
| 12 » char buf[100]; | 16 const struct tm* restrict tm, |
| 13 » wchar_t wbuf[100]; | 17 locale_t loc) { |
| 14 » wchar_t *p; | 18 size_t l, k; |
| 15 » const char *t_mb; | 19 char buf[100]; |
| 16 » const wchar_t *t; | 20 wchar_t wbuf[100]; |
| 17 » int plus; | 21 wchar_t* p; |
| 18 » unsigned long width; | 22 const char* t_mb; |
| 19 » for (l=0; l<n; f++) { | 23 const wchar_t* t; |
| 20 » » if (!*f) { | 24 int plus; |
| 21 » » » s[l] = 0; | 25 unsigned long width; |
| 22 » » » return l; | 26 for (l = 0; l < n; f++) { |
| 23 » » } | 27 if (!*f) { |
| 24 » » if (*f != '%') { | 28 s[l] = 0; |
| 25 » » » s[l++] = *f; | 29 return l; |
| 26 » » » continue; | 30 } |
| 27 » » } | 31 if (*f != '%') { |
| 28 » » f++; | 32 s[l++] = *f; |
| 29 » » if ((plus = (*f == '+'))) f++; | 33 continue; |
| 30 » » width = wcstoul(f, &p, 10); | 34 } |
| 31 » » if (*p == 'C' || *p == 'F' || *p == 'G' || *p == 'Y') { | 35 f++; |
| 32 » » » if (!width && p!=f) width = 1; | 36 if ((plus = (*f == '+'))) |
| 33 » » } else { | 37 f++; |
| 34 » » » width = 0; | 38 width = wcstoul(f, &p, 10); |
| 35 » » } | 39 if (*p == 'C' || *p == 'F' || *p == 'G' || *p == 'Y') { |
| 36 » » f = p; | 40 if (!width && p != f) |
| 37 » » if (*f == 'E' || *f == 'O') f++; | 41 width = 1; |
| 38 » » t_mb = __strftime_fmt_1(&buf, &k, *f, tm, loc); | 42 } else { |
| 39 » » if (!t_mb) break; | 43 width = 0; |
| 40 » » k = mbstowcs(wbuf, t_mb, sizeof wbuf / sizeof *wbuf); | 44 } |
| 41 » » if (k == (size_t)-1) return 0; | 45 f = p; |
| 42 » » t = wbuf; | 46 if (*f == 'E' || *f == 'O') |
| 43 » » if (width) { | 47 f++; |
| 44 » » » for (; *t=='+' || *t=='-' || (*t=='0'&&t[1]); t++, k--); | 48 t_mb = __strftime_fmt_1(&buf, &k, *f, tm, loc); |
| 45 » » » width--; | 49 if (!t_mb) |
| 46 » » » if (plus && tm->tm_year >= 10000-1900) | 50 break; |
| 47 » » » » s[l++] = '+'; | 51 k = mbstowcs(wbuf, t_mb, sizeof wbuf / sizeof *wbuf); |
| 48 » » » else if (tm->tm_year < -1900) | 52 if (k == (size_t)-1) |
| 49 » » » » s[l++] = '-'; | 53 return 0; |
| 50 » » » else | 54 t = wbuf; |
| 51 » » » » width++; | 55 if (width) { |
| 52 » » » for (; width > k && l < n; width--) | 56 for (; *t == '+' || *t == '-' || (*t == '0' && t[1]); t++, k--) |
| 53 » » » » s[l++] = '0'; | 57 ; |
| 54 » » } | 58 width--; |
| 55 » » if (k >= n-l) k = n-l; | 59 if (plus && tm->tm_year >= 10000 - 1900) |
| 56 » » wmemcpy(s+l, t, k); | 60 s[l++] = '+'; |
| 57 » » l += k; | 61 else if (tm->tm_year < -1900) |
| 58 » } | 62 s[l++] = '-'; |
| 59 » if (n) { | 63 else |
| 60 » » if (l==n) l=n-1; | 64 width++; |
| 61 » » s[l] = 0; | 65 for (; width > k && l < n; width--) |
| 62 » } | 66 s[l++] = '0'; |
| 63 » return 0; | 67 } |
| 68 if (k >= n - l) |
| 69 k = n - l; |
| 70 wmemcpy(s + l, t, k); |
| 71 l += k; |
| 72 } |
| 73 if (n) { |
| 74 if (l == n) |
| 75 l = n - 1; |
| 76 s[l] = 0; |
| 77 } |
| 78 return 0; |
| 64 } | 79 } |
| 65 | 80 |
| 66 size_t wcsftime(wchar_t *restrict wcs, size_t n, const wchar_t *restrict f, cons
t struct tm *restrict tm) | 81 size_t wcsftime(wchar_t* restrict wcs, |
| 67 { | 82 size_t n, |
| 68 » return __wcsftime_l(wcs, n, f, tm, CURRENT_LOCALE); | 83 const wchar_t* restrict f, |
| 84 const struct tm* restrict tm) { |
| 85 return __wcsftime_l(wcs, n, f, tm, CURRENT_LOCALE); |
| 69 } | 86 } |
| 70 | 87 |
| 71 weak_alias(__wcsftime_l, wcsftime_l); | 88 weak_alias(__wcsftime_l, wcsftime_l); |
| OLD | NEW |