Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , 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: <42BC60E5.1DA7215B@dessent.net> Date: Fri, 24 Jun 2005 12:37:09 -0700 From: Brian Dessent MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: strptime error when setting a different TimeZone with export TZ=UTC References: <200506241818 DOT j5OII4wg032180 AT smtp DOT hispeed DOT ch> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 Luca Wullschleger wrote: > Hi everybody. I have a very specific problem and I'm looking for someone > giving me a solution. I'm afriad this is operator error on your part. > struct tm try; Here 'try' starts out as a regular automatic variable, with all of its fields set to arbitrary (undefined) values. > if ((char *)strptime(date,"%d/%b/%Y:%T",&try) == NULL) { Here you call strptime() to fill in the values of 'try', however the strptime function has the semantics that it will only fill in the members of struct tm that it is asked to parse. This means that after the call, some of the members still have undefined values. Specifically, the members tm_wday, tm_yday, and tm_isdst will contain garbage. > ts2 = mktime(&try) - atoi(timezone)*3600; And here you pass this value of 'try' that still has uninitialized values to mktime(), the result of which will be undefined as well. I think you were just lucky that it worked in the case where TZ was not set, but in general once you encounter the situation where you pass uninitialized data to a function, all bets are off because your program is invalid C. If you change the line above to "struct tm try = { 0 };" or otherwise initialize it somehow, then I think you will get the desired functionality. 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/