diff options
author | Ron Yorston <rmy@pobox.com> | 2020-08-03 16:09:38 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2020-08-03 16:09:38 +0100 |
commit | 597dc43c9c8dad0daf9d4d0648e3e83c352b4ffd (patch) | |
tree | 827d838970a659bc7ce869c86886779c59a9312c | |
parent | 8b47fa3e20606a03cb2b9e79a329214a69add325 (diff) | |
download | busybox-w32-597dc43c9c8dad0daf9d4d0648e3e83c352b4ffd.tar.gz busybox-w32-597dc43c9c8dad0daf9d4d0648e3e83c352b4ffd.tar.bz2 busybox-w32-597dc43c9c8dad0daf9d4d0648e3e83c352b4ffd.zip |
win32: update strptime(3) implementation
Update to latest code from gnulib. This adds a '%q' (quarter) field
descriptor.
Remove the 'neg' variable from the code to handle the '%z' (timezone)
field descriptor. Since our struct tm lacks a tm_gmtoff member '%z' is
only supported "for reasons of symmetry". Since the computed value is
never used there's no need to negate it.
-rw-r--r-- | win32/strptime.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/win32/strptime.c b/win32/strptime.c index c1164184d..75e5e34f7 100644 --- a/win32/strptime.c +++ b/win32/strptime.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* Copyright (C) 2002, 2004-2005, 2007, 2009-2014 Free Software Foundation, | 1 | /* Copyright (C) 2002, 2004-2005, 2007, 2009-2020 Free Software Foundation, |
2 | Inc. | 2 | Inc. |
3 | This file is part of the GNU C Library. | 3 | This file is part of the GNU C Library. |
4 | 4 | ||
@@ -13,10 +13,10 @@ | |||
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License along | 15 | You should have received a copy of the GNU General Public License along |
16 | with this program; if not, see <http://www.gnu.org/licenses/>. */ | 16 | with this program; if not, see <https://www.gnu.org/licenses/>. */ |
17 | 17 | ||
18 | /* | 18 | /* |
19 | * File from gnulib (http://www.gnu.org/software/gnulib/), processed with | 19 | * File from gnulib (https://www.gnu.org/software/gnulib/), processed with |
20 | * coan source -U_LIBC -U_NL_CURRENT -UHAVE_TM_GMTOFF strptime.c | 20 | * coan source -U_LIBC -U_NL_CURRENT -UHAVE_TM_GMTOFF strptime.c |
21 | * and lightly edited. | 21 | * and lightly edited. |
22 | */ | 22 | */ |
@@ -119,11 +119,12 @@ day_of_the_week (struct tm *tm) | |||
119 | difference between this data in the one on TM and so determine | 119 | difference between this data in the one on TM and so determine |
120 | the weekday. */ | 120 | the weekday. */ |
121 | int corr_year = 1900 + tm->tm_year - (tm->tm_mon < 2); | 121 | int corr_year = 1900 + tm->tm_year - (tm->tm_mon < 2); |
122 | int corr_quad = corr_year / 4; | ||
122 | int wday = (-473 | 123 | int wday = (-473 |
123 | + (365 * (tm->tm_year - 70)) | 124 | + (365 * (tm->tm_year - 70)) |
124 | + (corr_year / 4) | 125 | + corr_quad |
125 | - ((corr_year / 4) / 25) + ((corr_year / 4) % 25 < 0) | 126 | - ((corr_quad + (corr_quad < 0)) / 25 - (corr_quad < 0)) |
126 | + (((corr_year / 4) / 25) / 4) | 127 | + ((corr_quad / 25) / 4) |
127 | + __mon_yday[0][tm->tm_mon] | 128 | + __mon_yday[0][tm->tm_mon] |
128 | + tm->tm_mday - 1); | 129 | + tm->tm_mday - 1); |
129 | tm->tm_wday = ((wday % 7) + 7) % 7; | 130 | tm->tm_wday = ((wday % 7) + 7) % 7; |
@@ -176,7 +177,7 @@ __strptime_internal (const char *rp, const char *fmt, struct tm *tm, | |||
176 | } | 177 | } |
177 | 178 | ||
178 | /* Any character but '%' must be matched by the same character | 179 | /* Any character but '%' must be matched by the same character |
179 | in the iput string. */ | 180 | in the input string. */ |
180 | if (*fmt != '%') | 181 | if (*fmt != '%') |
181 | { | 182 | { |
182 | match_char (*fmt++, *rp++); | 183 | match_char (*fmt++, *rp++); |
@@ -313,6 +314,15 @@ __strptime_internal (const char *rp, const char *fmt, struct tm *tm, | |||
313 | return NULL; | 314 | return NULL; |
314 | } | 315 | } |
315 | break; | 316 | break; |
317 | case 'q': | ||
318 | /* Match quarter of year. GNU extension. */ | ||
319 | get_number (1, 4, 1); | ||
320 | tm->tm_mon = (val - 1) * 3; | ||
321 | tm->tm_mday = 1; | ||
322 | have_mon = 1; | ||
323 | have_mday = 1; | ||
324 | want_xday = 1; | ||
325 | break; | ||
316 | case 'r': | 326 | case 'r': |
317 | if (!recursive (HERE_T_FMT_AMPM)) | 327 | if (!recursive (HERE_T_FMT_AMPM)) |
318 | return NULL; | 328 | return NULL; |
@@ -418,7 +428,6 @@ __strptime_internal (const char *rp, const char *fmt, struct tm *tm, | |||
418 | specify hours. If fours digits are used, minutes are | 428 | specify hours. If fours digits are used, minutes are |
419 | also specified. */ | 429 | also specified. */ |
420 | { | 430 | { |
421 | bool neg; | ||
422 | int n; | 431 | int n; |
423 | 432 | ||
424 | val = 0; | 433 | val = 0; |
@@ -426,7 +435,7 @@ __strptime_internal (const char *rp, const char *fmt, struct tm *tm, | |||
426 | ++rp; | 435 | ++rp; |
427 | if (*rp != '+' && *rp != '-') | 436 | if (*rp != '+' && *rp != '-') |
428 | return NULL; | 437 | return NULL; |
429 | neg = *rp++ == '-'; | 438 | ++rp; |
430 | n = 0; | 439 | n = 0; |
431 | while (n < 4 && *rp >= '0' && *rp <= '9') | 440 | while (n < 4 && *rp >= '0' && *rp <= '9') |
432 | { | 441 | { |
@@ -447,8 +456,6 @@ __strptime_internal (const char *rp, const char *fmt, struct tm *tm, | |||
447 | } | 456 | } |
448 | if (val > 1200) | 457 | if (val > 1200) |
449 | return NULL; | 458 | return NULL; |
450 | if (neg) | ||
451 | val = -val; | ||
452 | } | 459 | } |
453 | break; | 460 | break; |
454 | case 'E': | 461 | case 'E': |
@@ -462,7 +469,7 @@ __strptime_internal (const char *rp, const char *fmt, struct tm *tm, | |||
462 | case 'O': | 469 | case 'O': |
463 | /* We don't have an alternative number format. Just use | 470 | /* We don't have an alternative number format. Just use |
464 | the normal format. */ | 471 | the normal format. */ |
465 | if (strchr("deHImMSUWVwy", *fmt) == NULL) | 472 | if (strchr("deHImMqSUWVwy", *fmt) == NULL) |
466 | /* This is an illegal format. */ | 473 | /* This is an illegal format. */ |
467 | return NULL; | 474 | return NULL; |
468 | 475 | ||