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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fusl/src/time/utime.c ('k') | fusl/src/unistd/_exit.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fusl/src/time/wcsftime.c
diff --git a/fusl/src/time/wcsftime.c b/fusl/src/time/wcsftime.c
new file mode 100644
index 0000000000000000000000000000000000000000..638e64f6b445772931bb63171082ebaaaccc861a
--- /dev/null
+++ b/fusl/src/time/wcsftime.c
@@ -0,0 +1,71 @@
+#include <wchar.h>
+#include <time.h>
+#include <locale.h>
+#include "locale_impl.h"
+#include "libc.h"
+
+const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm *tm, locale_t loc);
+
+size_t __wcsftime_l(wchar_t *restrict s, size_t n, const wchar_t *restrict f, const struct tm *restrict tm, locale_t loc)
+{
+ size_t l, k;
+ char buf[100];
+ wchar_t wbuf[100];
+ wchar_t *p;
+ const char *t_mb;
+ const wchar_t *t;
+ int plus;
+ unsigned long width;
+ for (l=0; l<n; f++) {
+ if (!*f) {
+ s[l] = 0;
+ return l;
+ }
+ if (*f != '%') {
+ s[l++] = *f;
+ continue;
+ }
+ f++;
+ if ((plus = (*f == '+'))) f++;
+ width = wcstoul(f, &p, 10);
+ if (*p == 'C' || *p == 'F' || *p == 'G' || *p == 'Y') {
+ if (!width && p!=f) width = 1;
+ } else {
+ width = 0;
+ }
+ f = p;
+ if (*f == 'E' || *f == 'O') f++;
+ t_mb = __strftime_fmt_1(&buf, &k, *f, tm, loc);
+ if (!t_mb) break;
+ k = mbstowcs(wbuf, t_mb, sizeof wbuf / sizeof *wbuf);
+ if (k == (size_t)-1) return 0;
+ t = wbuf;
+ if (width) {
+ for (; *t=='+' || *t=='-' || (*t=='0'&&t[1]); t++, k--);
+ width--;
+ if (plus && tm->tm_year >= 10000-1900)
+ s[l++] = '+';
+ else if (tm->tm_year < -1900)
+ s[l++] = '-';
+ else
+ width++;
+ for (; width > k && l < n; width--)
+ s[l++] = '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;
+}
+
+size_t wcsftime(wchar_t *restrict wcs, size_t n, const wchar_t *restrict f, const struct tm *restrict tm)
+{
+ return __wcsftime_l(wcs, n, f, tm, CURRENT_LOCALE);
+}
+
+weak_alias(__wcsftime_l, wcsftime_l);
« 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