Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Jun 2000 00:03:04 -0400
From:      Garance A Drosihn <drosih@rpi.edu>
To:        Chuck Robey <chuckr@picnic.mat.net>
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:  <v0421010fb57c7be7a8c7@[128.113.24.47]>
In-Reply-To: <Pine.BSF.4.21.0006252033030.318-100000@picnic.mat.net>
References:  <Pine.BSF.4.21.0006252033030.318-100000@picnic.mat.net>

next in thread | previous in thread | raw e-mail | index | archive | help
At 8:35 PM -0400 6/25/00, Chuck Robey wrote:
>On Sun, 25 Jun 2000, Garance A Drosihn wrote:
>
> > At 12:28 AM -0400 6/25/00, Chuck Robey wrote:
> > > 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.
> >
> > 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.
> >
> > 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?

Almost.  The thing is, I am almost certain I *have* had this same
conversation before in a freebsd mailing list.  While looking for
whatever that conversation was, I came across the thread you get
if you search freebsd-current for:
     Bogus errno twiddling by lstat

I said "almost", because it's not just system calls which fiddle
around with errno.  I may have missed the original context of the
current thread, but my vague hand-waving memory was not limiting
itself to system calls.  From the earlier thread in freebsd-current,
for instance, there was a message from Bill Fenner which said:

     Someone else wrote:
     > So the question becomes: "At what point can I expect a
     > library routine to behave like a system call"?

     When it's documented to do so.

     > I *thought* that there were some ISO/POSIX requirements
     > that errno not be touched in non-error cases

     ISO/ANSI C says that library functions may modify errno unless
     the standard says otherwise.  The standard says otherwise for
     at least the math functions, which set errno to things like
     EDOM and ERANGE or leave it alone if no error occurred, and
     the calling sequence

         errno = 0;
         y = asin(x);
         if (errno == EDOM) {
                 ...
         }

     is meant to work in that situation.  However, normal library
     functions are explicitly allowed to modify errno even if no
     error occurs.

Note that in this case you would have to explicitly set errno
before calling the library routine, if you wanted to check
errno after calling the library routine.  That's all I was
saying (although this thread isn't the one I remember having
earlier).  The above message seems to be in reply to Terry
Lambert, who gave some other examples.  In reviewing the whole
thread, my basic impression is that errno is a mechanism that
no one particularly likes, but no one has come up with a
replacement for, either.  I don't know how much things have
changed since that thread (June 1998).

This isn't quite the situation I was trying to remember, but it
will do good enough that I can go home now without feeling like
I am merely ducking the question...  :-)


---
Garance Alistair Drosehn           =   gad@eclipse.acs.rpi.edu
Senior Systems Programmer          or  drosih@rpi.edu
Rensselaer Polytechnic Institute


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?v0421010fb57c7be7a8c7>