www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/26/02:58:22

Date: Wed, 26 May 1999 09:56:06 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Dlanor Blytkerchan <dlanor AT dds DOT nl>
cc: djgpp AT delorie DOT com
Subject: Re: srand() or time()
In-Reply-To: <l03130304b36f36eea8f5@[145.98.116.154]>
Message-ID: <Pine.SUN.3.91.990526095545.29401E-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Mon, 24 May 1999, Dlanor Blytkerchan wrote:

> When stepping through this in RHIDE, watching errno like a hawk, immediatly
> after srand(time(0)); errno is set to 22 (ENOENT)

That's because `time' looks for the timezone files on your system, to
correctly handle the DST (Daylight Saving Time) rules.  I guess you
didn't install djtzn202.zip, right?  (See section 22.19 of the FAQ for
more details.)

I believe there's nothing wrong in this behavior of `time'.  The ANSI
C standard says this:

   ... The value of `errno' may be set to nonzero by a library
   function call whether or not there is an error, provided the use of
   `errno' is not documented in the description of the function in
   [the ANSI C Standard].

Since the description of `time' in the ANSI C Standard doesn't include
any references to `errno', `time' is free to assign non-zero values to
`errno'.

> (and thus causes my
> program to believe there's an error, which it wisely ignores).

I think this is a bug in your program.  Programs should only examine
`errno' if they have other, independent means to indicate that the
last function call failed.  In the case of `time', it will return -1
if it fails; *then* you could use `errno' value to find out why it
failed.

- Raw text -


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