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