Re: ctime && asctime(localtime())

From: Akuma/Chris Baggett/DOOMer (doomer@BAYOU.COM)
Date: 12/22/97


ok, i think i may have solved my own problem.

from what i tried out, it seems that ctime/asctime(localtime())
uses a static buffer to write out the string, and then returns the
pointer to that string.
so it would cause this small problem.
I don't know if it's only on my mud or not, but this seems to be the case.
the solution i used, was to just str_dup() it, and then
FREE() it at the end of the function. which is no big deal, unless someone
can find a problem with it.
anyway, just to answer my own question:
str_dup() the pointer, then FREE/free it later.

l8r.
have a Merry Christmas and a Happy New Year.

Akuma the Raging Coder.


At 12:00 AM 12/23/97 -0600, you wrote:
>question.
>
>Is there any reason for ctime/asctime to all of a sudden
>go buggy?
>
>I was attempting to log a simple string (similar to what typeing UPTIME
>in the mud would produce) and for some reason
>the Up since ___ part is always
>the current time.
>
>So i placed a few logs, and grep'd a bit for any possible changes to
>boot_time and couldn't find any problems
>I even kept a working backup copy on my home computer,
>and it looks exactly the same except for the log()'s
>it worked fine before. but now for some reason it's doing this.
>
>here's the logs i placed.
>in do_date
>in the else { } block
>
>log("boot_time = %d", (int)boot_time);
>log("boot_time = %s", ctime(&boot_time));
>
>and here's the output i got:
>
>Dec 23 00:40:04 :: boot_time = 882855598
>Dec 23 00:40:04 :: boot_time = Tue Dec 23 00:40:04 1997
>Dec 23 00:40:04 :: boot_time = 882855598
>Dec 23 00:40:04 :: boot_time = Tue Dec 23 00:40:04 1997
>Dec 23 00:40:05 :: boot_time = 882855598
>Dec 23 00:40:05 :: boot_time = Tue Dec 23 00:40:05 1997
>Dec 23 00:40:06 :: boot_time = 882855598
>Dec 23 00:40:06 :: boot_time = Tue Dec 23 00:40:06 1997
>Dec 23 00:41:00 :: boot_time = 882855598
>Dec 23 00:41:00 :: boot_time = Tue Dec 23 00:41:00 1997
>Dec 23 00:42:00 :: boot_time = 882855598
>Dec 23 00:42:00 :: boot_time = Tue Dec 23 00:42:00 1997
>// and here's what gets me, i've waited almost TEN minutes
>// and it STILL changes the string no matter what!?!?!
>Dec 23 00:50:00 :: boot_time = 882855598
>Dec 23 00:50:00 :: boot_time = Tue Dec 23 00:50:00 1997
>
>the same thing happens if i change ctime() to asctime(localtime())
>(seeing as how they are the same thing i couldn't see how they were
different)
>
>any clues on this one?
>obviously i'm not changing boot_time anywhere, but the string is different
>everytime i print it out.
>WTF?
>this is currently running fine on my mud.
>it prints out the correct time and everything, but why not here?
>the code hasn't been changed in any way, except for the log()'s
>(and the ctime() thing)
>
>any ideas would be helpful.
>
>thanks.
>Akuma the Raging Coder
>
>  +------------------------------------------------------------+
>  | "The poets talk about love, but what I talk about is DOOM, |
>  |      because in the end, DOOM is all that counts." -       |
>  |   Alex Machine/George Stark/Stephen King, The Dark Half    |
>  |        "Nothing is IMPOSSIBLE, Just IMPROBABLE"            |
>  |   "Easier Said Than Done, But Better Done Than Said..."    |
>  +------------------------------------------------------------+
>
>
>     +------------------------------------------------------------+
>     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
>     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
>     +------------------------------------------------------------+
>
>
  +----------------------------------------------------------------+
  |     "Yea, though I code in the Valley of the Shadow of No      |
  | Documentation, I will fear no task: for thy C Book is with me" |
  |          "Nothing is IMPOSSIBLE, Just IMPROBABLE"              |
  |     "Easier Said Than Done, But Better Done Than Said..."      |
  +----------------------------------------------------------------+


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/08/00 PST