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

Unified Diff: fusl/src/time/getdate.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/ftime.c ('k') | fusl/src/time/gettimeofday.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fusl/src/time/getdate.c
diff --git a/fusl/src/time/getdate.c b/fusl/src/time/getdate.c
new file mode 100644
index 0000000000000000000000000000000000000000..89f21699125655eb27b1efa780a4e6f7ef0755de
--- /dev/null
+++ b/fusl/src/time/getdate.c
@@ -0,0 +1,45 @@
+#include <time.h>
+#include <pthread.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int getdate_err;
+
+struct tm *getdate(const char *s)
+{
+ static struct tm tmbuf;
+ struct tm *ret = 0;
+ char *datemsk = getenv("DATEMSK");
+ FILE *f = 0;
+ char fmt[100], *p;
+ int cs;
+
+ pthread_setcancelstate(PTHREAD_CANCEL_DEFERRED, &cs);
+
+ if (!datemsk) {
+ getdate_err = 1;
+ goto out;
+ }
+
+ f = fopen(datemsk, "rbe");
+ if (!f) {
+ if (errno == ENOMEM) getdate_err = 6;
+ else getdate_err = 2;
+ goto out;
+ }
+
+ while (fgets(fmt, sizeof fmt, f)) {
+ p = strptime(s, fmt, &tmbuf);
+ if (p && !*p) {
+ ret = &tmbuf;
+ goto out;
+ }
+ }
+
+ getdate_err = 7;
+out:
+ if (f) fclose(f);
+ pthread_setcancelstate(cs, 0);
+ return ret;
+}
« no previous file with comments | « fusl/src/time/ftime.c ('k') | fusl/src/time/gettimeofday.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698