lynx-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: LYNX-DEV How do I clear errno?


From: Larry W. Virden, x2487
Subject: Re: LYNX-DEV How do I clear errno?
Date: Fri, 3 Apr 1998 05:01:16 -0500

1. In the implementations that I have seen, errno is an int, so you could
just say 

errno = 0;

2. Others have mentioned that one does not generally set errno.  I
would add that you also should not be _testing_ errno unless an error
condition has been returned.

So, using code similar to 

if (open(string, argument) == -1) {
        if (errno == FIRSTERRNOMACRO)
                do(this);
        else if (errno == NEXTERRNOMACRO)
                do(that);
        else
                do(default);
}

would be how you would structure things.  Be sure to never use hard coded
errno values when the function in question specifies one of the errno.h
macros, because there's no guarantee that the specific number is the
same from OS to OS.

With this approach, you would never look at errno unless you already
knew there was a problem; with that in mind, no clearing of errno is
needed.

HOWEVER, you DO need to consider this - do not expect errno to have the
value you need if you call ANY function between the bad return code and
the use of errno, since some other function may do something to it.
Instead, you might try

if (open(string, argument) == -1) {
        hlderrno = errno;
        fprintf(stderr, "DANGER, WILL ROBINSON!\n");
        if (hlderrno == FIRSTERRNOMACRO)
                do(this);
        else if (hlderrno == NEXTERRNOMACRO)
                do(that);
        else
                do(default);
}
-- 
Larry W. Virden                 INET: address@hidden
<URL:http://www.teraform.com/%7Elvirden/> <*> O- "We are all Kosh."
Unless explicitly stated to the contrary, nothing in this posting should 
be construed as representing my employer's opinions.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]