Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 25 Jun 2000 20:35:55 -0400 (EDT)
From:      Chuck Robey <chuckr@picnic.mat.net>
To:        Garance A Drosihn <drosih@rpi.edu>
Cc:        Peter.Bohne@hboc.com, fengyue@bluerose.windmoon.nu, andrew@ugh.net.au, hackers@FreeBSD.ORG
Subject:   RE: libc_r/_read(), should the errno be reset to 0?
Message-ID:  <Pine.BSF.4.21.0006252033030.318-100000@picnic.mat.net>
In-Reply-To: <v0421010db57c10345a22@[128.113.24.47]>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 25 Jun 2000, Garance A Drosihn wrote:

> At 12:28 AM -0400 6/25/00, Chuck Robey wrote:
> >On Fri, 23 Jun 2000, Bohne, Peter wrote:
> >
> > > True enough.  That's the best advice.  However, your original
> > > post indicated an expectation on your part that errno would
> > > be somehow automatically reset to 0 before a system call, which
> > > is definitely *not* the case.  You have to clear it - the kernel
> > > does not do it for you.
> >
> >Why would you bother to clear it?  You don't check errno to determine
> >fail/success, you check the function return.  If it returns fail, then
> >errno is going to be correct whether or not you bothered to reset it or
> >not.  Setting it to zero might give you a warm fuzzy feeling, but if
> >you're correctly detected errors, it's not going to change anything.
> 
> There are times when clearing errno is significant.  What you said is
> correct for the routine which actually calls the system routine (is it
> some *_read() routine here?), but some library routines will call
> several system routines, and only return an error to caller (of that
> library routine) in some cases.
> 
> For instance, it might stat() some file, which sets errno if that
> file does not exist.  To the library routine, it isn't really an
> error if that file does not exist, it just creates the file or
> perhaps skips over some optional processing.  Later on, it may
> return an error due to some OTHER condition, a condition which
> did not set errno.  Someone checking errno will think that "file
> does not exist" is the problem, when the problem is elsewhere.
> 
> As usual with this topic, I can never remember a good example of
> this, except that I know I've run into it on some occasions...

If there is an example, tell me and I'll fix it.  I can't comment,
Garance, on a nebulous "I know it's out there somewhere" type of reply.  I
know how it's supposed to work, and how it does in all cases I've seen.

Anyone who knows of an exception, bail Garance out here.  Context is, a
system call that requires setting errno to zero before making the call in
order to get a correct error return.

Fair enough, Garance?


----------------------------------------------------------------------------
Chuck Robey            | Interests include C & Java programming, FreeBSD,
chuckr@picnic.mat.net  | electronics, communications, and signal processing.

New Year's Resolution:  I will not sphroxify gullible people into looking up
fictitious words in the dictionary.
----------------------------------------------------------------------------



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0006252033030.318-100000>