projects
/
musl
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
remove hand-written crt1.s and Scrt1.s files for all archs
[musl]
/
src
/
time
/
strptime.c
diff --git
a/src/time/strptime.c
b/src/time/strptime.c
index
d9481d1
..
f41f55f
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,17
+6,19
@@
#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;
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++;
@@
-40,6
+41,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;
@@
-112,8
+117,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
+136,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 = &tm->tm_year;
+ 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;
@@
-155,7
+168,7
@@
char *strptime(const char *s, const char *f, struct tm *tm)
if (*s == '+') s++;
else if (*s == '-') neg=1, s++;
if (!isdigit(*s)) return 0;
if (*s == '+') s++;
else if (*s == '-') neg=1, s++;
if (!isdigit(*s)) return 0;
- for (i=0; i<w && isdigit(*s); i++)
+ for (
*dest=
i=0; i<w && isdigit(*s); i++)
*dest = *dest * 10 + *s++ - '0';
if (neg) *dest = -*dest;
*dest -= adj;
*dest = *dest * 10 + *s++ - '0';
if (neg) *dest = -*dest;
*dest -= adj;
@@
-165,6
+178,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
+189,9
@@
char *strptime(const char *s, const char *f, struct tm *tm)
;
}
}
;
}
}
+ if (want_century) {
+ 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;
}