delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2011/06/15/14:07:09

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,T_TO_NO_BRKTS_FREEMAIL
X-Spam-Check-By: sourceware.org
Message-ID: <4DF8F426.7040705@gmail.com>
Date: Wed, 15 Jun 2011 14:04:22 -0400
From: Tod <listacctc AT gmail DOT com>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: localtime
References: <4DF8CF3D DOT 40104 AT gmail DOT com> <4DF8EA79 DOT 2060404 AT gmail DOT com> <20110615173847 DOT GB23078 AT ednor DOT casa DOT cgf DOT cx> <4DF8EF9F DOT 4090906 AT gmail DOT com> <20110615174805 DOT GC23078 AT ednor DOT casa DOT cgf DOT cx>
In-Reply-To: <20110615174805.GC23078@ednor.casa.cgf.cx>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.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 06/15/2011 1:48 PM, Christopher Faylor wrote:
> On Wed, Jun 15, 2011 at 01:45:03PM -0400, Tod wrote:
>> On 06/15/2011 1:38 PM, Christopher Faylor wrote:
>>> On Wed, Jun 15, 2011 at 01:23:05PM -0400, Tod wrote:
>>>> On 06/15/2011 11:26 AM, Tod wrote:
>>>>> Hi,
>>>>>
>>>>> Has anything change in regards to the C localtime function since 2007?
>>>>> I've got a program with a function that uses it to present the date and
>>>>> time that I just changed. The time isn't appearing only the date.
>>>>>
>>>>> No errors, no dumps, just no time. Most bizarre.
>>>>>
>>>>>
>>>>> TIA - Tod
>>>>
>>>>
>>>> Incidentally, here's how I'm valuing the time.  Worked with the 2007
>>>> version of cygwin1.dll (not that I'm blaming cygwin):
>>>>
>>>> char * getTime(char *tout)
>>>>      {
>>>>       time_t      now;
>>>>       struct      tm tim;
>>>>
>>>>       now = time(NULL);
>>>>       tim = *(localtime(&now));
>>>>       strftime(tout,strlen(tout),"%m/%d/%Y:%H:%M:%S",&tim);
>>>>
>>>>       return(tout);
>>>>      }
>>>>
>>>> tout is a 128 byte character array.
>>>
>>> If that's really what you're using then strlen(tout) seems obviously
>>> wrong.  It should be 128.
>>
>> Won't strlen(tout) resolve to 128?
>
> No.  It resolves to the length of the string, whatever that happens to
> be.  If it was "abc", then strlen would == 3.
>


Ok, right - duh.  Let me back up a couple of steps.

I'm passing a 128 byte char array.  I allocated it to provide enough 
room for the date/time stamp this function is returning.  strlen(tout) 
will resolve to the length of the tout string.

You said above that I shouldn't be using strlen(tout) and instead I 
should be passing 128.  Would I be better off using sizeof(tout) instead?

Also, the code has always worked.  I just recompiled it recently.  Now 
the date works but the time isn't appearing.  What could be causing that?


Thanks!

--
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