diff options
author | Yuri Pankov <yuripv@FreeBSD.org> | 2018-10-17 14:51:43 +0000 |
---|---|---|
committer | Yuri Pankov <yuripv@FreeBSD.org> | 2018-10-17 14:51:43 +0000 |
commit | eb144aa007e4ef03af9b1f2fa7cea29916abf82f (patch) | |
tree | 97997f33646c06910937e14acd61336be7c2f3a7 /lib | |
parent | 0455a92bcb39a17ac56fbd5d36de87d36409d761 (diff) |
Notes
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/stdtime/strptime.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/lib/libc/stdtime/strptime.c b/lib/libc/stdtime/strptime.c index 78cef6bf839e4..e011a7fe8dc8c 100644 --- a/lib/libc/stdtime/strptime.c +++ b/lib/libc/stdtime/strptime.c @@ -95,6 +95,7 @@ _strptime(const char *buf, const char *fmt, struct tm *tm, int *GMTp, int i, len; int flags; int Ealternative, Oalternative; + int century, year; const struct lc_time_T *tptr = __get_current_time_locale(locale); static int start_of_month[2][13] = { {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}, @@ -102,6 +103,8 @@ _strptime(const char *buf, const char *fmt, struct tm *tm, int *GMTp, }; flags = FLAG_NONE; + century = -1; + year = -1; ptr = fmt; while (*ptr != 0) { @@ -146,10 +149,8 @@ label: i += *buf - '0'; len--; } - if (i < 19) - return (NULL); - tm->tm_year = i * 100 - TM_YEAR_BASE; + century = i; flags |= FLAG_YEAR; break; @@ -527,13 +528,9 @@ label: len--; } if (c == 'Y') - i -= TM_YEAR_BASE; - if (c == 'y' && i < 69) - i += 100; - if (i < 0) - return (NULL); + century = i / 100; + year = i % 100; - tm->tm_year = i; flags |= FLAG_YEAR; break; @@ -611,6 +608,17 @@ label: } } + if (century != -1 || year != -1) { + if (year == -1) + year = 0; + if (century == -1) { + if (year < 69) + year += 100; + } else + year += century * 100 - TM_YEAR_BASE; + tm->tm_year = year; + } + if (!(flags & FLAG_YDAY) && (flags & FLAG_YEAR)) { if ((flags & (FLAG_MONTH | FLAG_MDAY)) == (FLAG_MONTH | FLAG_MDAY)) { |