In message: <[EMAIL PROTECTED]> Julian Cowley <[EMAIL PROTECTED]> writes: : M. Warner Losh wrote: : > In message: <[EMAIL PROTECTED]> : > Daniel Molina Wegener <[EMAIL PROTECTED]> 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; : }
Well, to portably[*] use some of the math(3) routines in libc, you need to set it to 0 before calling them (strtol, et al come to mind). Otherwise you are correct. In fact, it is generally incorrect to write code like: errno = 0; close(fd); if (errno != 0) because errno isn't necessarily valid even if it has changed in that case... Warner _______________________________________________ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "[EMAIL PROTECTED]"