delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/27/08:00:47

Sender: demmer AT delorie DOT com
Message-ID: <356BFF78.5E0D7F68@LSTM.Ruhr-UNI-Bochum.De>
Date: Wed, 27 May 1998 13:56:40 +0200
From: Thomas Demmer <demmer AT LSTM DOT Ruhr-UNI-Bochum DOT De>
Organization: Lehrstuhl fuer Stroemungsmechanik
MIME-Version: 1.0
To: erikyyy AT studbox DOT uni-stuttgart DOT de
CC: djgpp AT delorie DOT com
Subject: Re: BUG in readdir libc function
References: <19980526221202 DOT B1173 AT vulcain DOT yyydom>

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

As I have recently learned, ANSI just says that
errno must be set to zero at the program start.
Functions that produce no error may not
set it to any value. So you must say
  errno = 0;
  if ( !readdir ){
    if (errno)
       puts("Shit");


-- 
Ciao
Tom

*************************************************************
* Thomas Demmer                                             *
* Lehrstuhl fuer Stroemungsmechanik                         *
* Ruhr-Uni-Bochum                                           *
* Universitaetsstr. 150                                     *
* D-44780  Bochum                                           *
* Tel: +49 234 700 6434                                     *
* Fax: +49 234 709 4162                                     *
* http://www.lstm.ruhr-uni-bochum.de/~demmer                *
*************************************************************

- Raw text -


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