Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: kelsey@vesta01.SLAC.Stanford.EDU (Mike Kelsey)
Subject: Bug? in Alpha/OSF1 -- strptime() case sensitive
Date: 1997/09/16	[thread overview]
Message-ID: <5vmjft$5pr$1@nntp.Stanford.EDU> (raw)


[Followup-To: poster.  I will summarize a solution if I get one.]

I have encountered a discrepancy between the man page for strptime(3) and
the function's actual operation.  The man page says that the function is not
case sensitive when matching input items such as month or weekday names.  In
fact it is, as the following code demonstrates:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

main() {
  char inDT[50], outDT[50];	/* Date-time stamp buffers */
  struct tm tmbuf;		/* Buffer for time value found */
  time_t intime;		/* Date-time stamp from mktime() */
  int i, qcap;

  intime = time(NULL);
  strftime(inDT,sizeof inDT,"%d-%b-%Y:%H:%M:%S",localtime(&intime));
  for (i=0; i<strlen(inDT); inDT[i++] = toupper(inDT[i]));
  printf("Input date string %s\n",inDT);

#ifdef STRPTIME_BUG
  for (i=0, qcap=TRUE; i<strlen(inDT); i++)	/* Capitalize month name */
    if (isalpha(inDT[i]))
      inDT[i] = (!qcap) ? tolower(inDT[i])
	                : (qcap = FALSE, toupper(inDT[i]));
#endif

  memset(&tmbuf,0,sizeof tmbuf);
  if ((strptime(inDT,"%d-%b-%y:%H:%M:%S",&tmbuf) == NULL) &&	/* Not YY */
      (strptime(inDT,"%d-%b-%Y:%H:%M:%S",&tmbuf) == NULL)) {	/* Not YYYY */
    fprintf(stderr,"Invalid date string %s.\n",inDT);
    exit(EXIT_FAILURE);
  }

  intime = mktime(&tmbuf);		/* Convert struct to time_t */
  strftime(outDT, sizeof outDT, "%d-%b-%Y:%H:%M:%S", localtime(&intime));
  printf("Converted to %s\n", outDT);
}


Here is a sample session showing what happens.

% touch test_strptime.c
% gmake test_strptime
cc test_strptime.c -o test_strptime
% test_strptime
Input date string 16-SEP-1997:11:27:02
Invalid date string 16-SEP-1997:11:27:02.
% touch test_strptime.c
% gmake test_strptime "CFLAGS=-DSTRPTIME_BUG"
cc -DSTRPTIME_BUG test_strptime.c -o test_strptime
% test_strptime
Input date string 16-SEP-1997:11:27:47
Converted to 16-Sep-1997:12:27:47

The input date has "SEP" in all caps, which ought to be just fine.  With the
"#ifdef" code block not compiled (first case), this is reported as INVALID.
If I go through and convert "SEP" to "Sep" (second case) then strptime()
works just fine.

Has anyone else seen this bug?  Is it something I should report to Digital,
or has it been fixed in a later version of Alpha/OSF?

						-- Michael Kelsey
-- 
[ My opinions are not endorsed by SLAC, UBC, or any other authority ]
 "I've seen things you people wouldn't believe.  Attack ships on fire
  off the shoulder of Orion. I've watched C-beams glitter in the dark
  near the Tannhauser Gate.   All these moments will be lost in time,
  like tears in rain."                                   -- Roy Batty



                 reply	other threads:[~1997-09-16  4:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox