[Hackers] Re: any way to reset errno?
Julian Cowley
julian at lava.net
Sun Feb 6 14:16:01 PST 2005
M. Warner Losh wrote:
> In message: <20050206132124.GA746 at daemon.unete.cl>
> Daniel Molina Wegener <dmw at unete.cl> writes:
> : Any way to reset errno?
>
> errno = 0;
>
> Routines that return an error status in errno generally don't set it
> to 0 to mean no error.
Which implies errno should never need to be set to zero since the
convention is to only look at errno if a system call fails. The only
time errno needs to be explicitly set (to any value) is when preserving
the error value between system calls. Such as:
if (write(fd, buf, len) < 0) {
int saved_errno;
saved_errno = errno;
close(fd); /* ignore any error */
errno = saved_errno;
return -1;
}
More information about the freebsd-hackers
mailing list