delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/06/24/16:08:28

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
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
Message-ID: <42BC692A.2E583360@dessent.net>
Date: Fri, 24 Jun 2005 13:12:26 -0700
From: Brian Dessent <brian AT dessent DOT net>
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: strptime error when setting a different TimeZone with export TZ=UTC
References: <062420051945 DOT 26249 DOT 42BC62D30002FD110000668922007358340A050E040D0C079D0A AT comcast DOT net>
X-Spam-Report: -5.9/5.0 ---- Start SpamAssassin results * -3.3 ALL_TRUSTED Did not pass through any untrusted hosts * -2.6 BAYES_00 BODY: Bayesian spam probability is 0 to 1% * [score: 0.0000] * 0.0 AWL AWL: From: address is in the auto white-list ---- End SpamAssassin results
X-IsSubscribed: yes
Reply-To: cygwin AT cygwin DOT com

Eric Blake wrote:

> Not necessarily.  According to POSIX, a strptime implementation is allowed
> (but not necessarily recommended) to set all fields of try, even the ones
> not related to what was parsed:
> 
> "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." -
> http://www.opengroup.org/susv3xsh/strptime.html

I guess that could explain why it works on linux then.  Obviously, it's
not portable to rely on that behavior though.

> initialized properly.  And pre-initializing to all 0s (as in struct tm try = {0,};)
> does not work, either, since the rules of <time.h> state that tm_month
> must be 1 - 12.  In short, struct tm is a nightmare to use, but we are
> stuck with it for standardized backwards compatibility.

Actually tm_mon must be in the range [0,11].  You might have been
thinking of tm_mday which unlike all the others is 1-based, [1,31].  In
this particular example though it's probably sufficient to initialize tm
with { 0 } since both tm_mday and tm_mon should be filled in by strptime
on success.  However, to truly be correct you'd have to check not only
that strptime didn't return NULL, but that it parsed the entire format
string and stopped at the expected point rather than failing early.

Brian

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

- Raw text -


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