Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: fusl/src/time/wcsftime.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fusl/src/time/utime.c ('k') | fusl/src/unistd/_exit.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include <wchar.h>
2 #include <time.h>
3 #include <locale.h>
4 #include "locale_impl.h"
5 #include "libc.h"
6
7 const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm * tm, locale_t loc);
8
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)
10 {
11 size_t l, k;
12 char buf[100];
13 wchar_t wbuf[100];
14 wchar_t *p;
15 const char *t_mb;
16 const wchar_t *t;
17 int plus;
18 unsigned long width;
19 for (l=0; l<n; f++) {
20 if (!*f) {
21 s[l] = 0;
22 return l;
23 }
24 if (*f != '%') {
25 s[l++] = *f;
26 continue;
27 }
28 f++;
29 if ((plus = (*f == '+'))) f++;
30 width = wcstoul(f, &p, 10);
31 if (*p == 'C' || *p == 'F' || *p == 'G' || *p == 'Y') {
32 if (!width && p!=f) width = 1;
33 } else {
34 width = 0;
35 }
36 f = p;
37 if (*f == 'E' || *f == 'O') f++;
38 t_mb = __strftime_fmt_1(&buf, &k, *f, tm, loc);
39 if (!t_mb) break;
40 k = mbstowcs(wbuf, t_mb, sizeof wbuf / sizeof *wbuf);
41 if (k == (size_t)-1) return 0;
42 t = wbuf;
43 if (width) {
44 for (; *t=='+' || *t=='-' || (*t=='0'&&t[1]); t++, k--);
45 width--;
46 if (plus && tm->tm_year >= 10000-1900)
47 s[l++] = '+';
48 else if (tm->tm_year < -1900)
49 s[l++] = '-';
50 else
51 width++;
52 for (; width > k && l < n; width--)
53 s[l++] = '0';
54 }
55 if (k >= n-l) k = n-l;
56 wmemcpy(s+l, t, k);
57 l += k;
58 }
59 if (n) {
60 if (l==n) l=n-1;
61 s[l] = 0;
62 }
63 return 0;
64 }
65
66 size_t wcsftime(wchar_t *restrict wcs, size_t n, const wchar_t *restrict f, cons t struct tm *restrict tm)
67 {
68 return __wcsftime_l(wcs, n, f, tm, CURRENT_LOCALE);
69 }
70
71 weak_alias(__wcsftime_l, wcsftime_l);
OLDNEW
« no previous file with comments | « fusl/src/time/utime.c ('k') | fusl/src/unistd/_exit.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698