Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 23 Jun 2000 12:11:50 -0400
From:      "Bohne, Peter" <Peter.Bohne@hboc.com>
To:        "'andrew@ugh.net.au'" <andrew@ugh.net.au>, "Bohne, Peter" <Peter.Bohne@hboc.com>
Cc:        FengYue <fengyue@bluerose.windmoon.nu>, hackers@FreeBSD.ORG
Subject:   RE: libc_r/_read(), should the errno be reset to 0?
Message-ID:  <35BEC7ED0A15D21199F000805F6F6D6A01CB00E2@bldexc01ntms.clinicom.com>

next in thread | raw e-mail | index | archive | help
Anytime you make a call that can potentially set errno, and you are planning
to *check* errno afterwards, you have to set errno to 0 yourself.  Once a
system call sets errno to some (any) value, errno will just retain that
value until the next system call that fails and sets errno.  AFAIK *nothing*
sets errno to 0, ever.  (Except probably when your process first starts -
errno probably gets initialized to 0, altho I don't even count on that.
Someone else on the list may know about this.)  *Always* set errno to 0
before you do your call if you want to inspect the value of errno after the
call.  I don't have the original post in front of me, but wasn't the problem
that you wanted to check errno after a 2nd read() that had succeeded?  If
so, then errno will still have EAGAIN in it if the 1st read() had put it
there, even tho the 2nd read succeeded.

Maybe *I'm* the one missing something ... :-)

pete

> -----Original Message-----
> From: andrew@ugh.net.au [mailto:andrew@ugh.net.au]
> Sent: Friday, June 23, 2000 9:49 AM
> To: Bohne, Peter
> Cc: FengYue; hackers@FreeBSD.ORG
> Subject: RE: libc_r/_read(), should the errno be reset to 0?
> 
> 
> 
> 
> On Fri, 23 Jun 2000, Bohne, Peter wrote:
> 
> > This means that *you* should set errno to 0 just before you 
> do the read
> > call.  At this point, you no longer care what it had been before.
> 
> Why set it at all? If read returns an error then it will set 
> it for you
> and if read doesn't return an error it doesn't really matter whats in
> errno.
> 
> Am I missing something?
> 
> Andrew
> 
> 
> 
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-hackers" in the body of the message
> 



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?35BEC7ED0A15D21199F000805F6F6D6A01CB00E2>