delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/05/26/21:06:50

Mime-Version: 1.0
To: erikyyy AT studbox DOT uni-stuttgart DOT de
From: Nate Eldredge <nate AT cartsys DOT com>
Subject: Re: BUG in readdir libc function
Cc: djgpp-workers AT delorie DOT com
Date: Tue, 26 May 1998 18:01:00 -0700
Message-ID: <19980527010023.AAO19094@ppp114.cartsys.com>

At 10:12  5/26/1998 +0200, erikyyy AT studbox DOT uni-stuttgart DOT de wrote:
>my linux libc docu sais, that readdir returns 0 on error
>and may set errno to
>
>`EBADF'           The DIRSTREAM argument is not valid. 
>
>since 0 may also mean, that the directory is at the end, there must
>be a way to distinguish between those two cases.
>
>i think the right way to do this is
>
>if (!readdir(.......)) if (errno) die("system shit");
>	else printf("directory ends");
>
>this doesn't work, because:
>
>
>readdir DOESN'T SET errno TO 0, if it returns 0 and the
>directory is at its end !!!!!!!!!!!!!!

Can somebody check what POSIX has to say about this?

Currently, `readdir' leaves `errno' unchanged when the end is reached. Thus,
you can get the desired behavior by setting `errno=0' yourself beforehand.
Is that what one's supposed to do?

In either case, the docs should reflect the behavior better.

Nate Eldredge
nate AT cartsys DOT com



- Raw text -


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