Module Name: src Committed By: ginsbach Date: Mon Jul 20 14:37:11 UTC 2015
Modified Files: src/lib/libc/time: strptime.c Log Message: KNF and additional comments To generate a diff of this commit: cvs rdiff -u -r1.45 -r1.46 src/lib/libc/time/strptime.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libc/time/strptime.c diff -u src/lib/libc/time/strptime.c:1.45 src/lib/libc/time/strptime.c:1.46 --- src/lib/libc/time/strptime.c:1.45 Wed Jul 15 13:54:38 2015 +++ src/lib/libc/time/strptime.c Mon Jul 20 14:37:11 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: strptime.c,v 1.45 2015/07/15 13:54:38 ginsbach Exp $ */ +/* $NetBSD: strptime.c,v 1.46 2015/07/20 14:37:11 ginsbach Exp $ */ /*- * Copyright (c) 1997, 1998, 2005, 2008 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: strptime.c,v 1.45 2015/07/15 13:54:38 ginsbach Exp $"); +__RCSID("$NetBSD: strptime.c,v 1.46 2015/07/20 14:37:11 ginsbach Exp $"); #endif #include "namespace.h" @@ -50,6 +50,10 @@ __weak_alias(strptime,_strptime) __weak_alias(strptime_l, _strptime_l) #endif +static const u_char *conv_num(const unsigned char *, int *, uint, uint); +static const u_char *find_string(const u_char *, int *, const char * const *, + const char * const *, int); + #define _TIME_LOCALE(loc) \ ((_TimeLocale *)((loc)->part_impl[(size_t)LC_TIME])) @@ -83,12 +87,14 @@ static const char * const nadt[5] = { "EDT", "CDT", "MDT", "PDT", "\0\0\0" }; -static const u_char *conv_num(const unsigned char *, int *, uint, uint); -static const u_char *find_string(const u_char *, int *, const char * const *, - const char * const *, int); - +/* + * Table to determine the ordinal date for the start of a month. + * Ref: http://en.wikipedia.org/wiki/ISO_week_date + */ static const int start_of_month[2][13] = { + /* non-leap year */ { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, + /* leap year */ { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } }; @@ -586,11 +592,13 @@ literal: if (!HAVE_YDAY(state) && HAVE_YEAR(state)) { if (HAVE_MON(state) && HAVE_MDAY(state)) { + /* calculate day of year (ordinal date) */ tm->tm_yday = start_of_month[isleap_sum(tm->tm_year, TM_YEAR_BASE)][tm->tm_mon] + (tm->tm_mday - 1); state |= S_YDAY; } else if (day_offset != -1) { - /* Set the date to the first Sunday (or Monday) + /* + * Set the date to the first Sunday (or Monday) * of the specified week of the year. */ if (!HAVE_WDAY(state)) { @@ -607,7 +615,9 @@ literal: if (HAVE_YDAY(state) && HAVE_YEAR(state)) { int isleap; + if (!HAVE_MON(state)) { + /* calculate month of day of year */ i = 0; isleap = isleap_sum(tm->tm_year, TM_YEAR_BASE); while (tm->tm_yday >= start_of_month[isleap][i]) @@ -620,13 +630,17 @@ literal: tm->tm_mon = i - 1; state |= S_MON; } + if (!HAVE_MDAY(state)) { + /* calculate day of month */ isleap = isleap_sum(tm->tm_year, TM_YEAR_BASE); tm->tm_mday = tm->tm_yday - start_of_month[isleap][tm->tm_mon] + 1; state |= S_MDAY; } + if (!HAVE_WDAY(state)) { + /* calculate day of week */ i = 0; week_offset = first_wday_of(tm->tm_year); while (i++ <= tm->tm_yday) {