From owner-freebsd-current@FreeBSD.ORG Wed Nov 26 04:44:31 2003 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 869B516A4CE; Wed, 26 Nov 2003 04:44:31 -0800 (PST) Received: from stork.mail.pas.earthlink.net (stork.mail.pas.earthlink.net [207.217.120.188]) by mx1.FreeBSD.org (Postfix) with ESMTP id 88DE243FD7; Wed, 26 Nov 2003 04:44:30 -0800 (PST) (envelope-from tlambert2@mindspring.com) Received: from user-38lc18e.dialup.mindspring.com ([209.86.5.14] helo=mindspring.com) by stork.mail.pas.earthlink.net with asmtp (SSLv3:RC4-MD5:128) (Exim 3.33 #1) id 1AOz0k-0003c4-00; Wed, 26 Nov 2003 04:43:20 -0800 Message-ID: <3FC49F7E.4C2C217A@mindspring.com> Date: Wed, 26 Nov 2003 04:41:34 -0800 From: Terry Lambert X-Mailer: Mozilla 4.79 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Maxime Henrion References: <20031123141408.GA1426@ratsnest.hole> <20031124174457.GB27782@madman.celabo.org> <20031124182322.GB621@wombat.fafoe.narf.at> <3FC40E19.6A2989B6@mindspring.com> <20031126095315.GH8404@elvis.mu.org> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-ELNK-Trace: b1a02af9316fbb217a47c185c03b154d40683398e744b8a49569e19862215bed9514ad8df3b8491ea2d4e88014a4647c350badd9bab72f9c350badd9bab72f9c cc: Stefan Farfeleder cc: "boyd, rounin" cc: current@freebsd.org Subject: Re: [PATCH] libc_r bug: successful close(2) sets errno to ENOTTY X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Nov 2003 12:44:31 -0000 Maxime Henrion wrote: > Terry Lambert wrote: > > > Wrong, counter-example: strtol(). > > > > Wrong; the standard specifies that the errno shall only be > > checked when the return value is -1. The exception in the > > strtol() case is only for presetting errno to 0 before you > > make the call, and making a check only following a -1 return. [ ... ] > The only cases where there is a _potential_ error returned by strtol() > is when it returns 0, LONG_MIN or LONG_MAX. So check it only in those cases. I don't see the problem with errno being set willy-nilly in a library to multiple different values in implementing some standards defined behaviour, so long as it's indicated correctly. > Moreover, the implementation may set errno to something > even when the conversion was successful. So, in strict ISO C, errno is > meaningful only if strtol() returns LONG_MIN or LONG_MAX. You should write your code to expect that a 0 return is not an error indicator, then. You know, real hardware would SIGFPE... > In any case, a return value of -1 does not mean anything for strtol(). Which is irrelevent to the discussion about whether or not a library is allowed to futz errno to non-0 any time it wants. We all know that the *only* reason this issue arose is that somone was writing bogus error checking code that did something like: errno = 0; (void)some_library_function_returning_neg_one_on_error(); if (errno != 0) { printf( "I should have checked my return value, but\n"); printf( "standards documents and man pages confuse me.\n"); } -- Terry