Date: Mon, 24 Nov 2003 11:44:57 -0600 From: "Jacques A. Vidrine" <nectar@FreeBSD.org> To: Enache Adrian <enache@rdslink.ro> Cc: current@freebsd.org Subject: Re: [PATCH] libc_r bug: successful close(2) sets errno to ENOTTY Message-ID: <20031124174457.GB27782@madman.celabo.org> In-Reply-To: <20031123141408.GA1426@ratsnest.hole> References: <20031123141408.GA1426@ratsnest.hole>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <errno.h> > 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. <URL:http://www.opengroup.org/onlinepubs/007904975/functions/errno.html> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20031124174457.GB27782>