Home | History | Annotate | Download | only in time
History log of /src/lib/libc/time/strptime.c
RevisionDateAuthorComments
 1.67  07-Jun-2024  riastradh libc/locale: Nix needless size_t casts.

No functional change intended. No binary change to aarch64 libc.

Prompted by code inspection around PR lib/58319.
 1.66  18-Mar-2024  riastradh strptime(3): Declare digit d as time_t.

This doesn't make a semantic difference -- d can only take on the ten
values {0,1,2,3,4,5,6,7,8,9}, and the arithmetic with it later all
comes out the same whether the type is unsigned or time_t, even if
time_t were int32_t instead of int64_t.

But it pacifies overzealous compilers used by downstream users of
this code. And while it's silly to use a much wider type (64-bit
signed) than is needed here to store a single digit, it doesn't
really hurt either (32-bit unsigned is much larger than needed too).

PR lib/58041
 1.65  16-Mar-2024  riastradh strptime(3): Reduce unnecessary indentation.

Post-fix tidying.

No functional change intended.

PR lib/58041
 1.64  16-Mar-2024  riastradh strptime(3): Avoid arithmetic overflow.

PR lib/58041
 1.63  21-Sep-2020  ginsbach branches: 1.63.6;
Correct range for ISO week conversion

The %V conversion range for strptime(3) should match the strftime(3)
conversion range. A valid ISO week is 1-53.
 1.62  24-Aug-2017  ginsbach branches: 1.62.6;
The military/nautical time zones were added following RFC 822 and RFC
2822 specifications. Unfortunately they are specified incorrectly in
RFC-822 and not very clearly in RFC 2822. RFC 1123 clearly states they
are specified incorrectly - counting the wrong way from UTC - in RFC
822. RFC 2822 just states they were implemented in a non-standard way.
Mea culpa for not noticing when originally implemented. Fix them so
the correct calculations are made.
 1.61  12-Aug-2017  ginsbach Fix a couple comments and a spacing nit.

- Change a XXX comment that no longer applies.
- Add a clarifying comment.
 1.60  15-May-2016  christos remove stray debugging.
 1.59  15-May-2016  christos Bail out if the string does not look like a timezone (is empty or does not
start with a letter or a number). tzparse("") or tzparse(".45") don't fail.
 1.58  31-Oct-2015  ginsbach Don't attempt to set TM_ZONE (name) for 'J' as isdst isn't known.
 1.57  31-Oct-2015  christos make %Z and %z understand the same strings.
 1.56  30-Oct-2015  ginsbach Add 'J' (Juliett) as military time zone name meaning the local time zone.
 1.55  30-Oct-2015  christos drop stray #endif
 1.54  30-Oct-2015  christos revert timezone() ifdef; it is wrong (pointed out by ginsbach)
 1.53  30-Oct-2015  ginsbach ISO 8601 and RFC 3339 specify that an offset can be up to 23:59 and
not 12:00 east/west. Just proves that one shouldn't use other
implementations as a canonical reference. Thanks to all who pointed
this out.
 1.52  30-Oct-2015  ginsbach Reject timezone offsets more than 12 hours (east or west).
 1.51  29-Oct-2015  christos - use #defined constants (from gisbach)
- back to setting tm_zone to NULL when we don't know.
 1.50  29-Oct-2015  christos PR/50380: Balazs Scheidler: strptime() returns incorrect values in tm_gmtoff
- Always offset in seconds.
- Handle arbitrary timezones.
 1.49  09-Oct-2015  christos Release 2015g - 2015-10-01 00:39:51 -0700

Changes affecting code

localtime no longer mishandles America/Anchorage after 2037.
(Thanks to Bradley White for reporting the bug.)

The localtime module allows the variables 'timezone', 'daylight',
and 'altzone' to be in common storage shared with other modules,
and declares them in case the system <time.h> does not.
(Problems reported by Kees Dekker.)

On platforms with tm_zone, strftime.c now assumes it is not NULL.
This simplifies the code and is consistent with zdump.c.
(Problem reported by Christos Zoulas.)

Changes affecting documentation

The tzfile man page now documents that transition times denote the
starts (not the ends) of the corresponding time periods.
(Ambiguity reported by Bill Seymour.)
 1.48  29-Jul-2015  ginsbach Only apply am/pm adjustment to tm_hour when it has actually been parsed.
 1.47  22-Jul-2015  ginsbach More KNF style changes -- consistent use of whitespace in #defines.
 1.46  20-Jul-2015  ginsbach KNF and additional comments
 1.45  15-Jul-2015  ginsbach Don't set state when parsing any timezone (%z) information. The '+' in
this case isn't the same as the FreeBSD '%+' str[fp]time() (GNU) extension.
 1.44  14-Jul-2015  ginsbach Set S_WDAY state for %u (same as it is set for %w).
 1.43  13-Jul-2015  ginsbach Switch to using isleap() and isleap_sum() macros from <tzfile.h> to be
consistent with strftime.c and localtime.c.
 1.42  08-Jul-2015  ginsbach Add macros to clarify what (parse) state is needed to calculate 'missing'
tm fields.
 1.41  08-Jul-2015  ginsbach Rename flags to state since that is really what flags tracks (parse state).
 1.40  03-Jul-2015  christos PR/50009: David CARLIER: Enhance strptime to fill out more fields when it
can. From FreeBSD.
 1.39  06-Apr-2015  ginsbach Add UTC as a synonym for GMT (%Z). [from FreeBSD]
 1.38  17-May-2013  joerg Provide explicit LC_C_LOCALE accessor and drop the various NULL checks.
Provide LC_GLOBAL_LOCALE in a way that works with all locale functions.
Merge constant data used by the initial global locale and the C locale.
Drop function call layer for _current_locale() and directly return the
locale reference, not a pointer to it. Use protected access for global
variables, so that libc references can avoid the GOT overhead.
 1.37  21-Apr-2013  joerg Store time-specific locale data directly in the locale.
Ad dstrftime_l, strftime_lz and strptime_l.
 1.36  13-Mar-2012  christos branches: 1.36.2;
PR/45989: Martin Husemann: lint invocation does include -w only on i386

- turn lint -w for all the platforms after fixing the lint warnings.
- add _DIAGASSERTS() for casts that would assign values to types that
would not fit.
- change types, add casts
- change into ansii prototypes
- turn on _DIAGNOSTIC for libc (during current, to be eliminated for release
builds)

approved by core@
 1.35  14-Dec-2009  matt branches: 1.35.6;
Back errant change due to botched merge.
 1.34  14-Dec-2009  matt Suppress a warning if time_t is __int64_t
 1.33  24-May-2009  ginsbach Add %s to strptime(3) to make symmetric with strftime(3).
 1.32  01-May-2009  ginsbach Extend %z to support all RFC-2822 timezone formats.
 1.31  04-Nov-2008  christos branches: 1.31.2; 1.31.4;
don't forget to use neg.
 1.30  04-Nov-2008  christos we don't need *
 1.29  04-Nov-2008  christos Our new syslogd seems to want to depend on %z which is a gnu extension.
- While here, add all the rest of gnu extensions: %g, %G, %u.
- Fix long standing bug where %Z would not work because "private.h" was
not included. (Hi Brian!)
 1.28  28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.27  25-Apr-2008  ginsbach Add %F the ISO 8601 date format which is equivalent to %Y-%m-%d. This
format character is supported for reasons of symmetry with strftime(3).
FreeBSD and GNU versions of strptime(3) both support %F.
 1.26  24-Apr-2008  ginsbach Add support for %Z ala FreeBSD and some other strptime(3) implementations.
Reviewed by christos.
 1.25  29-Nov-2005  christos branches: 1.25.18;
WARNS=4
 1.24  05-Mar-2005  dsl Some more optimisations - I must stop looking at this file!
Update copyright to include 2005
(I have a compleetly different version, but it is only a few 100 bytes
smaller due to a 560 byte data area.)
 1.23  04-Mar-2005  dsl A going-over with the optimiser, save over 500 bytes.
I think this is enough to get rescue_tiny to fit again.
While there fix some bugs:
- %y failed to subtract 1900 from tm_year
- %p (am/pm) only worked at the end of the string
- %E% was treated at %% (ie match a % character)
regression test being added....
 1.22  20-Dec-2000  christos fix u_char -> char and char -> u_char casts.
 1.21  19-Dec-2000  cgd Newer GCCs give warnings when the result of preprocessor token pasting
is not itself a valid (single) preprocessor token. In other words, don't
use __CONCAT() to add a structure member name to a pointer dereference.
 1.20  07-Jul-2000  itohy Passing "char" values to ctype(3) functions is problematic.
If an argument of a ctype function is outside "unsigned char"
and if it is not EOF, the behavior is undefined.

The isascii(3) is the sole exception of above and it was used to
be used to check a value was valid for other ctype functions in
ancient systems. On modern systems, the ctype functions take
all values of "unsigned char", and this check is obsolete and
even wrong for non-ASCII systems. However, we leave the isascii()
untouched for now, so as not to change the current behavior.
 1.19  22-Jan-2000  mycroft Delint.
Remove trailing ; from uses of __weak_alias(). The macro inserts this if
needed.
 1.18  29-Apr-1999  tv Use correct number of digits as described in lib/7001. This brings us
pretty close to UNIX98, but %U and %W still don't work.
 1.17  15-Nov-1998  christos branches: 1.17.2;
delint
 1.16  07-Sep-1998  kleink Cosmetical changes, and squash some lint.
 1.15  20-Aug-1998  veego Fix new egcs warnings (might be used uninitialized).
 1.14  05-May-1998  tv As inspired by PR #5268 from jpo@easterngraphics.com:
- make string comparisons case-insensitive
- add description of whitespace in the format string
- note that %t and %n match no whitespace as well as some whitespace
- change wording of standard to say "includes all requirements of"
instead of "conforms to" XPG4 as our %y is extended beyond XPG4
 1.13  19-Mar-1998  tv Fixes from PRs 5056 and 5161, partly rethought:
- %C and %y can be used in conjunction properly, though %y can have its
old behaviour if used without %C
- %I formats hous 0..11 with 0 representing "12"; this is correct both
with and without am/pm (%p rule fixed to compensate)
- %j fixed for range [0..365] in struct tm
- %m fixed for range [0..11] in struct tm
- %S fixed for range [0..61] in struct tm
 1.12  20-Jan-1998  mycroft Pull in tzfile.h.
 1.11  20-Jan-1998  mycroft Update dates.
 1.10  20-Jan-1998  mycroft The rollover for the previous is 1969, not 1970.
 1.9  20-Jan-1998  mycroft Fix an old comment
 1.8  20-Jan-1998  mycroft Treat 2-digit year < 70 as year - 2000, per XPG.
 1.7  21-Jul-1997  jtc branches: 1.7.2;
If port provides __weak_alias(), provide an Standard C and POSIX pure
identifier namespace by renaming non standard functions and variables
such that they have a leading underscore. The library will use those
names internally. Weak aliases are used to provide the original names
to the API.

This is only the first part of this change. It is most of the functions
which are implemented in C for all NetBSD ports. Subsequent changes are
to add the same support to the remaining C files, to assembly files, and
to the automagically generated assembly source used for system calls.
When all of the above is done, ports with weak alias support should add
a definition for __weak_alias to <sys/cdefs.h>.
 1.6  13-Jul-1997  christos Fix RCSID's
 1.5  03-Jun-1997  kleink Nuke a spurious (but under !__STDC__ fatal) space from last commit.
 1.4  03-Jun-1997  kleink Replace some hand-crafted concatenation with the __CONCAT() macro.
 1.3  25-May-1997  kleink Rewritten from scratch. Implement missing conversions and provide support
for E and O modifiers, though our locale does not support `alternate'
conversions and formats - we just stick to the unmodified rules in that case.
 1.2  06-May-1997  kleink KNF.
 1.1  23-Apr-1997  mrg move str[fp]time into libc/time.
 1.7.2.2  05-May-1998  mycroft Pull up 1.13-1.14, per request of tv.
 1.7.2.1  29-Jan-1998  mellon Pull up 1.8-1.12 (mycroft)
 1.17.2.1  29-Apr-1999  perry pullup 1.17->1.18 (tv)
 1.25.18.1  18-May-2008  yamt sync with head.
 1.31.4.1  13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.31.2.2  04-Nov-2008  christos don't forget to use neg.
 1.31.2.1  04-Nov-2008  christos file strptime.c was added on branch christos-time_t on 2008-11-04 21:08:34 +0000
 1.35.6.2  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.35.6.1  17-Apr-2012  yamt sync with head
 1.36.2.1  23-Jun-2013  tls resync from head
 1.62.6.1  24-Aug-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1881):

lib/libc/time/strptime.c: revision 1.64 (patch)
lib/libc/time/strptime.c: revision 1.65 (patch)
lib/libc/time/strptime.c: revision 1.66 (patch)
tests/lib/libc/time/t_strptime.c: revision 1.16 (patch)

strptime(3): Exercise some edge cases in the automatic tests.

Unfortunately, we can't quite use strptime as a black box to detect
the cases that triggered undefined behaviour, because strptime just
fails in that case anyway since the number that would go in .tm_year
is far out of the representable range.
PR lib/58041

strptime(3): Avoid arithmetic overflow.
PR lib/58041

strptime(3): Reduce unnecessary indentation.
Post-fix tidying.
No functional change intended.
PR lib/58041

strptime(3): Declare digit d as time_t.

This doesn't make a semantic difference -- d can only take on the ten
values {0,1,2,3,4,5,6,7,8,9}, and the arithmetic with it later all
comes out the same whether the type is unsigned or time_t, even if
time_t were int32_t instead of int64_t.

But it pacifies overzealous compilers used by downstream users of
this code. And while it's silly to use a much wider type (64-bit
signed) than is needed here to store a single digit, it doesn't
really hurt either (32-bit unsigned is much larger than needed too).

PR lib/58041
 1.63.6.2  16-Apr-2024  martin Pull up following revision(s) (requested by riastradh in ticket #648):

lib/libc/time/strptime.c: revision 1.66

strptime(3): Declare digit d as time_t.

This doesn't make a semantic difference -- d can only take on the ten
values {0,1,2,3,4,5,6,7,8,9}, and the arithmetic with it later all
comes out the same whether the type is unsigned or time_t, even if
time_t were int32_t instead of int64_t.

But it pacifies overzealous compilers used by downstream users of
this code. And while it's silly to use a much wider type (64-bit
signed) than is needed here to store a single digit, it doesn't
really hurt either (32-bit unsigned is much larger than needed too).

PR lib/58041
 1.63.6.1  25-Mar-2024  martin Pull up following revision(s) (requested by riastradh in ticket #638):

lib/libc/time/strptime.c: revision 1.64
lib/libc/time/strptime.c: revision 1.65
tests/lib/libc/time/t_strptime.c: revision 1.16

strptime(3): Exercise some edge cases in the automatic tests.

Unfortunately, we can't quite use strptime as a black box to detect
the cases that triggered undefined behaviour, because strptime just
fails in that case anyway since the number that would go in .tm_year
is far out of the representable range.
PR lib/58041

strptime(3): Avoid arithmetic overflow.
PR lib/58041

strptime(3): Reduce unnecessary indentation.
Post-fix tidying.
No functional change intended.
PR lib/58041

RSS XML Feed