From owner-freebsd-hackers@FreeBSD.ORG Sun Feb 6 23:12:31 2005 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 441B816A4CE for ; Sun, 6 Feb 2005 23:12:31 +0000 (GMT) Received: from harmony.village.org (rover.village.org [168.103.84.182]) by mx1.FreeBSD.org (Postfix) with ESMTP id C477F43D45 for ; Sun, 6 Feb 2005 23:12:30 +0000 (GMT) (envelope-from imp@bsdimp.com) Received: from localhost (warner@rover2.village.org [10.0.0.1]) by harmony.village.org (8.13.1/8.13.1) with ESMTP id j16NBa4H078932; Sun, 6 Feb 2005 16:11:36 -0700 (MST) (envelope-from imp@bsdimp.com) Date: Sun, 06 Feb 2005 16:13:33 -0700 (MST) Message-Id: <20050206.161333.103235960.imp@bsdimp.com> To: julian@lava.net From: "M. Warner Losh" In-Reply-To: <4206971F.1020005@lava.net> References: <20050206132124.GA746@daemon.unete.cl> <20050206.142319.22504831.imp@bsdimp.com> <4206971F.1020005@lava.net> X-Mailer: Mew version 3.3 on Emacs 21.3 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit cc: freebsd-hackers@FreeBSD.ORG cc: dmw@unete.cl Subject: Re: [Hackers] Re: any way to reset errno? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Feb 2005 23:12:31 -0000 In message: <4206971F.1020005@lava.net> Julian Cowley writes: : M. Warner Losh wrote: : > In message: <20050206132124.GA746@daemon.unete.cl> : > Daniel Molina Wegener 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