On Fri, 29 Sep 2006 14:40:04 -0600
Theo de Raadt <[EMAIL PROTECTED]> wrote:

> > On 9/28/06, Paul Stoeber <[EMAIL PROTECTED]> wrote:
> > > Should a userland program be allowed to depend on errno==0 on entry
> > > to main()?  (At least one in the tree does.)
> > 
> > checking errno is the wrong way to ascertain whether a function had a
> > problem, so this shouldn't be a problem for a well written program.
> > 
> > on the other hand, code running before main is outside the scope of C
> > standard, and i think the standard at least implies errno should be 0
> > on entry, so we should fix/verify that too.
> 
> there is an even easier way to look at this:
> 
>       errno is only valid if something indicates that you should
>       be checking it
> 
> some functions are documented & defined so that when they return NULL,
> errno is set.
> 
> some functions are documented & defined so that when they return -1,
> errno is set.
> 
> if a function has not indicated that errno is now valid, then errno contains
> some previous result code which is absolutely irrelevant.
> 
> so fundamentally, the question being asked by the original poster is
> "can i check what is in errno whenever i want" has a simple answer: no.
> 
> therefore it is irrelevant what value is currently stored in errno.
> 
> if nothing told you to look at it, don't look at it.

I guess that means the answer to my original question is No.
I've sent a diff to [EMAIL PROTECTED]  Note especially usr.bin/head/head.c

Reply via email to