Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 1 Apr 2005 00:15:55 -0800 (PST)
From:      "ALeine" <aleine@austrosearch.net>
To:        ganbold@micom.mng.net
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: subtracting days from localtime problem 
Message-ID:  <200504010815.j318FtcY037434@marlena.vvi.at>

next in thread | raw e-mail | index | archive | help
ganbold@micom.mng.net wrote: 

> One more question, what will happen next time when
> time goes back in October?
> Does following line correct it as same as now?
> 
> /* make mktime(3) figure out whether DST is in effect */
> t->tm_isdst = -1;

Yes, it will work correctly. You can see what happens by
setting now to 1131131131 (where you currently have
now = time(NULL)). It's not an April Fools' Day joke, that
just happens to be an appropriate time in November. :-)

I also noticed a number of bugs in your code that you may
want to fix:

- memory leak: you are allocating memory with my_alloc(),
  but then you neither free(3) it nor keep track of it.
  You should remove my_alloc() and just create a buffer
  in main() and then pass it by reference to functions that
  need to modify its contents.

- with my_alloc() you basically reinvented strdup(3), see
  man 3 strdup for details. You do not need strdup(3) for
  what you want to achieve, just pass the buffer from main()
  by reference and then use snprintf(3) to modify its contents.

- snprintf(3) handles the size argument correctly, meaning
  that you should specify the full size of the string since
  at most size-1 characters are written with guaranteed NULL
  termination, see man 3 snprintf for details.

ALeine
___________________________________________________________________
WebMail FREE http://mail.austrosearch.net 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200504010815.j318FtcY037434>