delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2011/05/11/13:35:31

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Date: Wed, 11 May 2011 19:34:34 +0200
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: strptime doesn't fill in tm_wday and tm_yday.
Message-ID: <20110511173434.GE11041@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <4DCAA2A0 DOT 6040506 AT lysator DOT liu DOT se>
MIME-Version: 1.0
In-Reply-To: <4DCAA2A0.6040506@lysator.liu.se>
User-Agent: Mutt/1.5.21 (2010-09-15)
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On May 11 16:52, Peter Rosin wrote:
> Hello!
> 
> The following STC hints at a problem in strptime:
> 
> -----------------------8<----------------------------
> #include <stdio.h>
> #include <time.h>
> 
> int
> main(void)
> {
> 	/* seed tm with some garbage */
> 	struct tm tm = {
> 		0, 0, 0, /* s m h */
> 		0, 0, 0, /* d m y */
> 		290774, 2280577, 81
> 	};
> 	const char date[] = "2011-05-11 14:06:11";
> 
> 	if (!strptime(date, "%Y - %m - %d %T", &tm)) {
> 		fprintf(stderr, "strptime error\n");
> 		return 1;
> 	}
> 
> 	printf("%s", asctime(&tm));
> 	printf("tm_yday %d\n", tm.tm_yday);
> 	printf("tm_wday %d\n", tm.tm_wday);
> 	printf("tm_isdst %d\n", tm.tm_isdst);
> 	return 0;
> }
> -----------------------8<----------------------------
> 
> I get this output with Cygwin 1.7.9-1:
>  May 11 14:06:11 2011
> tm_yday 2280577
> tm_wday 290774
> tm_isdst 81
> 
> I expect:
> Wed May 11 14:06:11 2011
> tm_yday 130
> tm_wday 3
> tm_isdst whatever
> 
> I get the expected output on the Linux host I tried (with tm_isdst=81),
> but not on Solaris 10.
> 
> On Solaris 10 I get (for completeness):
> Sun May 11 14:06:11 2011
> tm_yday 0
> tm_wday 0
> tm_isdst 0
> 
> Opengroup has this to say about only filling in some fields:
> 
> 	"It is unspecified whether multiple calls to strptime()
> 	using the same tm structure will update the current
> 	contents of the structure or overwrite all contents of
> 	the structure. Conforming applications should make a
> 	single call to strptime() with a format and all data
> 	needed to completely specify the date and time being
> 	converted."
> 
> but I don't think it applies since indeed I do completely specify
> the date in my strptime call.

The Cygwin implementation of strptime is taken from NetBSD and enhanced
only in terms of support for the E and O modifiers.  The NetBSD and
OpenBSD versions also support a non-POSIX format specifier %u (day of
week, monday = 1).  Other than that, the Cygwin strptime behaves exactly
as the BSD implementation.  tm_wday is only set if you specify %a, %A or
%w.  tm_yday is only set if you specify %j.

Despite the example in the strptime man page of POSIX.1-2008, POSIX does
not specify that strptime has to fill out tm fields which are not also
specified in the format string.  You should better memset the tm
structure to 0 before calling strptime.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019