www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/08/21/16:13:59

Date: Sun, 20 Aug 1995 13:35:06 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Marc Singer <nbn.nbn.com!sapien!elf>
Cc: DJGPP List Alias <nbn.nbn.com!sapien!sun.soe.clarkson.edu!djgpp>
Subject: Re: mkdir and errno in V2

On Thu, 17 Aug 1995, Marc Singer wrote:

> It appears that the mkdir call does not clear errno on success.  My
> code is creating a new path by starting at the full length trying to
> create the directory.  On failure, it removes the last path element
> and tries again until it succeeds.  As soon as it does so, it replaces
> the path elements one at a time and creates the path one directory at
> a time.
> 
> Since it fails once, errno is ENOTDIR.  The successful mkdir calls do
> not clear this value so errno on exit from my procedure is still
> ENOTDIR.  I patch my procedure by clearing errno before each call to
> mkdir.

This is not a bug, IMHO.  AFAIK, errno is documented to hold the error 
code from the last system call *which failed*, and thus doesn't get 
cleared on a successful call.  Otherwise, if a library function calls 
several other library functions, you might get errno = 0 when the last 
call succeeds.  And the last call might be something stupid like writing 
an error message to the screen.

Programs which want to be sure that a certain library function failed, 
should clear errno before they call that library function, just as you've 
done.

- Raw text -


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