projects
/
musl
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
introduce namespace-safe rwlock aliases; use in pthread_key_create
[musl]
/
src
/
time
/
strptime.c
diff --git
a/src/time/strptime.c
b/src/time/strptime.c
index
488c08d
..
c54a0d8
100644
(file)
--- a/
src/time/strptime.c
+++ b/
src/time/strptime.c
@@
-1,4
+1,3
@@
-#include <stdio.h>
#include <stdlib.h>
#include <langinfo.h>
#include <time.h>
#include <stdlib.h>
#include <langinfo.h>
#include <time.h>
@@
-7,22
+6,29
@@
#include <string.h>
#include <strings.h>
#include <string.h>
#include <strings.h>
-char *strptime(const char *
s, const char *f, struct tm *
tm)
+char *strptime(const char *
restrict s, const char *restrict f, struct tm *restrict
tm)
{
{
- int i, w, neg, adj, min, range, *dest;
+ int i, w, neg, adj, min, range, *dest
, dummy
;
const char *ex;
size_t len;
const char *ex;
size_t len;
+ int want_century = 0, century = 0, relyear = 0;
while (*f) {
if (*f != '%') {
if (isspace(*f)) for (; *s && isspace(*s); s++);
else if (*s != *f) return 0;
else s++;
f++;
while (*f) {
if (*f != '%') {
if (isspace(*f)) for (; *s && isspace(*s); s++);
else if (*s != *f) return 0;
else s++;
f++;
+ continue;
}
f++;
if (*f == '+') f++;
}
f++;
if (*f == '+') f++;
- if (isdigit(*f)) w=strtoul(f, (void *)&f, 10);
- else w=-1;
+ if (isdigit(*f)) {
+ char *new_f;
+ w=strtoul(f, &new_f, 10);
+ f = new_f;
+ } else {
+ w=-1;
+ }
adj=0;
switch (*f++) {
case 'a': case 'A':
adj=0;
switch (*f++) {
case 'a': case 'A':
@@
-40,6
+46,10
@@
char *strptime(const char *s, const char *f, struct tm *tm)
if (!s) return 0;
break;
case 'C':
if (!s) return 0;
break;
case 'C':
+ dest = ¢ury;
+ if (w<0) w=2;
+ want_century |= 2;
+ goto numeric_digits;
case 'd': case 'e':
dest = &tm->tm_mday;
min = 1;
case 'd': case 'e':
dest = &tm->tm_mday;
min = 1;
@@
-63,6
+73,7
@@
char *strptime(const char *s, const char *f, struct tm *tm)
dest = &tm->tm_yday;
min = 1;
range = 366;
dest = &tm->tm_yday;
min = 1;
range = 366;
+ adj = 1;
goto numeric_range;
case 'm':
dest = &tm->tm_mon;
goto numeric_range;
case 'm':
dest = &tm->tm_mon;
@@
-83,6
+94,7
@@
char *strptime(const char *s, const char *f, struct tm *tm)
len = strlen(ex);
if (!strncasecmp(s, ex, len)) {
tm->tm_hour %= 12;
len = strlen(ex);
if (!strncasecmp(s, ex, len)) {
tm->tm_hour %= 12;
+ s += len;
break;
}
ex = nl_langinfo(PM_STR);
break;
}
ex = nl_langinfo(PM_STR);
@@
-90,6
+102,7
@@
char *strptime(const char *s, const char *f, struct tm *tm)
if (!strncasecmp(s, ex, len)) {
tm->tm_hour %= 12;
tm->tm_hour += 12;
if (!strncasecmp(s, ex, len)) {
tm->tm_hour %= 12;
tm->tm_hour += 12;
+ s += len;
break;
}
return 0;
break;
}
return 0;
@@
-112,8
+125,11
@@
char *strptime(const char *s, const char *f, struct tm *tm)
break;
case 'U':
case 'W':
break;
case 'U':
case 'W':
- //FIXME
- return 0;
+ /* Throw away result, for now. (FIXME?) */
+ dest = &dummy;
+ min = 0;
+ range = 54;
+ goto numeric_range;
case 'w':
dest = &tm->tm_wday;
min = 0;
case 'w':
dest = &tm->tm_wday;
min = 0;
@@
-128,16
+144,21
@@
char *strptime(const char *s, const char *f, struct tm *tm)
if (!s) return 0;
break;
case 'y':
if (!s) return 0;
break;
case 'y':
- //FIXME
- return 0;
+ dest = &relyear;
+ w = 2;
+ want_century |= 1;
+ goto numeric_digits;
case 'Y':
dest = &tm->tm_year;
if (w<0) w=4;
adj = 1900;
case 'Y':
dest = &tm->tm_year;
if (w<0) w=4;
adj = 1900;
+ want_century = 0;
goto numeric_digits;
case '%':
if (*s++ != '%') return 0;
break;
goto numeric_digits;
case '%':
if (*s++ != '%') return 0;
break;
+ default:
+ return 0;
numeric_range:
if (!isdigit(*s)) return 0;
*dest = 0;
numeric_range:
if (!isdigit(*s)) return 0;
*dest = 0;
@@
-165,6
+186,7
@@
char *strptime(const char *s, const char *f, struct tm *tm)
ex = nl_langinfo(min+i);
len = strlen(ex);
if (strncasecmp(s, ex, len)) continue;
ex = nl_langinfo(min+i);
len = strlen(ex);
if (strncasecmp(s, ex, len)) continue;
+ s += len;
*dest = i % range;
break;
}
*dest = i % range;
break;
}
@@
-175,5
+197,10
@@
char *strptime(const char *s, const char *f, struct tm *tm)
;
}
}
;
}
}
+ if (want_century) {
+ tm->tm_year = relyear;
+ if (want_century & 2) tm->tm_year += century * 100 - 1900;
+ else if (tm->tm_year <= 68) tm->tm_year += 100;
+ }
return (char *)s;
}
return (char *)s;
}