From owner-freebsd-hackers Sun Jun 25 17:38:43 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from picnic.mat.net (picnic.mat.net [206.246.122.133]) by hub.freebsd.org (Postfix) with ESMTP id 8905637B5A7 for ; Sun, 25 Jun 2000 17:38:38 -0700 (PDT) (envelope-from chuckr@picnic.mat.net) Received: from localhost (chuckr@localhost [127.0.0.1]) by picnic.mat.net (8.9.3/8.9.3) with ESMTP id UAA29636; Sun, 25 Jun 2000 20:35:56 -0400 (EDT) (envelope-from chuckr@picnic.mat.net) Date: Sun, 25 Jun 2000 20:35:55 -0400 (EDT) From: Chuck Robey To: Garance A Drosihn 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? In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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