Date: Sun, 06 Feb 2005 16:13:33 -0700 (MST) From: "M. Warner Losh" <imp@bsdimp.com> To: julian@lava.net Cc: dmw@unete.cl Subject: Re: [Hackers] Re: any way to reset errno? Message-ID: <20050206.161333.103235960.imp@bsdimp.com> In-Reply-To: <4206971F.1020005@lava.net> References: <20050206132124.GA746@daemon.unete.cl> <20050206.142319.22504831.imp@bsdimp.com> <4206971F.1020005@lava.net>
next in thread | previous in thread | raw e-mail | index | archive | help
In message: <4206971F.1020005@lava.net> Julian Cowley <julian@lava.net> writes: : M. Warner Losh wrote: : > In message: <20050206132124.GA746@daemon.unete.cl> : > Daniel Molina Wegener <dmw@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; : } 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050206.161333.103235960.imp>