NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
lib/55436: strptime does not process %G or %V
>Number: 55436
>Category: lib
>Synopsis: strptime does not process %G or %V
>Confidential: no
>Severity: serious
>Priority: low
>Responsible: lib-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Jun 30 19:45:00 +0000 2020
>Originator: jklowden
>Release: NetBSD 7.0
>Organization:
self
>Environment:
System: NetBSD oak.schemamania.org 7.0 NetBSD 7.0 (GENERIC.201509250726Z) amd64
Architecture: x86_64
Machine: amd64
>Description:
strptime(3) claims to honor %G and %V for ISO dates. In fact, both metacharacters are processed but ignored. strptime returns a pointer indicating the input was accepted, but the tm structure is unchanged.
>How-To-Repeat:
The attached program accepts three arguments: strptime format, strftime format, and a datestring. It prints the contents of the strptime struct tm output, and the strftime output from that tm. One example use:
$ t/strpftime W%V %D W26
tm = {
tm_sec = 0,
tm_min = 0,
tm_hour = 0,
tm_mday = 0,
tm_mon = 0,
tm_year = 0,
tm_wday = 0,
tm_yday = 0,
tm_isdst = 0 }
01/00/00 ('' unparsed)
It is perhaps interesting that the GNU strptime exhibits similar behavior.
>Fix:
No fix. Demonstration program:
[snip]
#include <ctype.h>
#include <err.h>
#include <getopt.h>
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
extern char *optarg;
int
main(int argc, char *argv[]) {
char output[80];
struct tm tm = {};
if( argc < 4 ) {
errx(EXIT_FAILURE, "syntax %s: strptime_fmt strftime_fmt datetime", argv[0]);
}
const char *ifmt = argv[1], *pend;
const char *ofmt = argv[2];
const char *input = argv[3];
if( (pend = strptime(input, ifmt, &tm)) == NULL ) {
errx(EXIT_FAILURE, "could not parse '%s' with '%s'", input, ifmt);
}
const char fmt[] =
" tm = {\n"
" tm_sec = %d, \n"
" tm_min = %d, \n"
" tm_hour = %d, \n"
" tm_mday = %d, \n"
" tm_mon = %d, \n"
" tm_year = %d, \n"
" tm_wday = %d, \n"
" tm_yday = %d, \n"
" tm_isdst = %d }\n";
printf(fmt,
tm.tm_sec,
tm.tm_min,
tm.tm_hour,
tm.tm_mday,
tm.tm_mon,
tm.tm_year,
tm.tm_wday,
tm.tm_yday,
tm.tm_isdst);
strftime(output, sizeof(output), ofmt, &tm);
printf("%s ('%s' unparsed)\n", output, pend);
return EXIT_SUCCESS;
}
[pins]
Home |
Main Index |
Thread Index |
Old Index