From owner-freebsd-current@FreeBSD.ORG Mon Nov 24 09:44:59 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 D36C416A4CE for ; Mon, 24 Nov 2003 09:44:59 -0800 (PST) Received: from gw.celabo.org (gw.celabo.org [208.42.49.153]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5E0A343F75 for ; Mon, 24 Nov 2003 09:44:58 -0800 (PST) (envelope-from nectar@celabo.org) Received: from madman.celabo.org (madman.celabo.org [10.0.1.111]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "madman.celabo.org", Issuer "celabo.org CA" (verified OK)) by gw.celabo.org (Postfix) with ESMTP id 04097548A3; Mon, 24 Nov 2003 11:44:58 -0600 (CST) Received: by madman.celabo.org (Postfix, from userid 1001) id 9AFB46D455; Mon, 24 Nov 2003 11:44:57 -0600 (CST) Date: Mon, 24 Nov 2003 11:44:57 -0600 From: "Jacques A. Vidrine" To: Enache Adrian Message-ID: <20031124174457.GB27782@madman.celabo.org> References: <20031123141408.GA1426@ratsnest.hole> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20031123141408.GA1426@ratsnest.hole> X-Url: http://www.celabo.org/ User-Agent: Mutt/1.5.4i-ja.1 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: Mon, 24 Nov 2003 17:44:59 -0000 On Sun, Nov 23, 2003 at 04:14:08PM +0200, Enache Adrian wrote: > $ cc close.c -o close && ./close > 0 > 0 > > $ cc close.c -lc_r -o close && ./close > 0 > 25 > > $ cat close.c > #include > main() > { > int fd = open("/dev/null", 1); > printf("%d\n", errno); > close(fd); > printf("%d\n", errno); > } > > This confuses rather badly applications which assume errno is meaningful. The application is broken. You must only check errno if you get an error indication from the library call. IEEE Std 1003.1, 2003 Edition says, in part: ``The value of errno should only be examined when it is indicated to be valid by a function's return value.'' Cheers, -- Jacques Vidrine NTT/Verio SME FreeBSD UNIX Heimdal nectar@celabo.org jvidrine@verio.net nectar@freebsd.org nectar@kth.se