Date: Thu, 11 Nov 1999 00:43:29 -0500 (EST) From: "Crist J. Clark" <cjc@cc942873-a.ewndsr1.nj.home.com> To: FreeBSD-gnats-submit@freebsd.org Cc: kevin.ruddy@powerdog.com Subject: bin/14817: strptime(3) '%C' conversion incorrect Message-ID: <199911110543.AAA45760@cc942873-a.ewndsr1.nj.home.com>
index | next in thread | raw e-mail
>Number: 14817
>Category: bin
>Synopsis: strptime(3) '%C' conversion incorrect
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Wed Nov 10 21:40:01 PST 1999
>Closed-Date:
>Last-Modified:
>Originator: Crist J. Clark
>Release: FreeBSD 3.3-STABLE i386
>Organization:
>Environment:
FreeBSD 3.3-STABLE. Default C library
>Description:
The strptime(3) function fills a time 'tm structure' from a
user's string using a format also provided by the user. However, the
'%C' conversion does not work as described in strftime(3) (which
strptime(3) references as containing the key for the conversions), nor
does a simple 'date +%C' return what the actual strptime(3) function
wants.
>How-To-Repeat:
A C fragment,
struct tm tm;
strptime("19","%C",&tm);
printf("%d\n",tm.tm_year);
Which fails using the existing code. It should return,
0
Or of we were to substitute "20" for "19",
100
>Fix:
I actually looked at strptime(3) to fix something else (it
can't read formats that run together, e.g "%y%j%H%M%S"), when I
noticed the way it handles '%C' is contradictory to the manpages and
date(1)'s operation. It was a quick fix. Patch:
--- /usr/src/lib/libc/stdtime/strptime.c Sun Aug 29 21:55:58 1999
+++ strptime.c Thu Nov 11 00:38:39 1999
@@ -1,4 +1,13 @@
/*
+ * 1999/11/11, cjclark@alum.mit.edu
+ *
+ * The '%C' conversion specification did not conform to the documentation
+ * in strftime(3) or in the operation of 'date +%C'. Fixed. The '%C'
+ * conversion demands _exactly_ two digits (like the output) and must
+ * be in the range 19-20. This 19-20 is converted to 0 or 100 being added
+ * to tm_year.
+ */
+/*
* Powerdog Industries kindly requests feedback from anyone modifying
* this function:
*
@@ -115,12 +124,6 @@
return 0;
break;
- case 'C':
- buf = _strptime(buf, Locale->date_fmt, tm);
- if (buf == 0)
- return 0;
- break;
-
case 'c':
buf = _strptime(buf, "%x %X", tm);
if (buf == 0)
@@ -163,7 +166,20 @@
return 0;
break;
- case 'j':
+ case 'C': /* "Century" (required to be two digits) */
+ if (!(isdigit((unsigned char)*buf) && isdigit((unsigned char)*(buf+1))))
+ return 0;
+ i = 10*(*buf++ - '0');
+ i += *buf++ - '0';
+
+ if ((i < 19) || (i > 20))
+ return 0;
+
+ tm->tm_year = i*100 - 1900;
+
+ break;
+
+ case 'j': /* Day of year */
if (!isdigit((unsigned char)*buf))
return 0;
>Release-Note:
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199911110543.AAA45760>
