From owner-freebsd-standards@FreeBSD.ORG Tue Jan 23 10:29:27 2007 Return-Path: X-Original-To: freebsd-standards@FreeBSD.ORG Delivered-To: freebsd-standards@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 7EA0416A40F for ; Tue, 23 Jan 2007 10:29:27 +0000 (UTC) (envelope-from giecrilj@stegny.2a.pl) Received: from shark.2a.pl (shark.2a.pl [195.117.102.3]) by mx1.freebsd.org (Postfix) with ESMTP id 6EE1E13C4C6 for ; Tue, 23 Jan 2007 10:29:24 +0000 (UTC) (envelope-from giecrilj@stegny.2a.pl) Received: from localhost (av.2a.pl [10.0.0.99]) by shark.2a.pl (Postfix) with ESMTP id AAF48B2526; Tue, 23 Jan 2007 11:29:22 +0100 (CET) Received: from shark.2a.pl ([10.0.0.3]) by localhost (av.2a.pl [10.0.0.99]) (amavisd-new, port 10024) with ESMTP id 90711-06; Tue, 23 Jan 2007 11:28:02 +0100 (CET) Received: from POCZTOWIEC (2a-gts [217.153.29.142]) by shark.2a.pl (Postfix) with ESMTP id AB0CBB24F0; Tue, 23 Jan 2007 11:29:11 +0100 (CET) From: =?iso-8859-2?Q?K=F8i=B9tof_=AEelechovski?= To: , References: <005301c73e6c$ba6ffd00$1a01080a@POCZTOWIEC> <200701230759.l0N7xCdg002571@lurza.secnetix.de> Date: Tue, 23 Jan 2007 11:29:13 +0100 Message-ID: <000401c73ed9$540afca0$1a01080a@POCZTOWIEC> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 11 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 In-Reply-To: <200701230759.l0N7xCdg002571@lurza.secnetix.de> Thread-Index: Acc+xre2cLUo/zLPTgyaxDCSk9FdTQABbDkg X-Virus-Scanned: amavisd-new at 2a.pl Cc: Subject: RE: return value of fprintf X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Jan 2007 10:29:27 -0000 Oh I see. =20 Indeed, the documentation was fixed to explain this in FreeBSD=A05.2=20 - I must have overlooked that. =20 My documentation is apparently taken from FreeBSD=A04.4. =20 Error return value is not documented here. I have run the code in a loop and the return value is periodically -1. =20 Interestingly enough,=20 although the stream error indicator is persistent,=20 it is not taken into account to prevent data corruption as in C++ = streams. =20 The reason may be that POSIX streams must set errno on failure=20 (this is *not* required by the ANSI standard) but there is no errno value to indicate that the error condition is set=20 (except EBADF -=20 but the POSIX standard should be modified to allow this extension,=20 since at present it only means "Bad file descriptor"). Thanks for your time Chris -----Original Message----- From: Oliver Fromme [mailto:olli@lurza.secnetix.de]=20 Sent: Tuesday, January 23, 2007 8:59 AM To: freebsd-standards@FreeBSD.ORG; giecrilj@stegny.2a.pl Subject: Re: return value of fprintf K?i?tof ?elechovski wrote: > The > h=3DFreeBSD+7-current&format=3Dhtml> fprintf manual page says it is = ANSI C > compatible and it returns the number of characters printed. >=20 > The latter is correct: I get printf("abcd") =3D=3D 4 even under = >/dev/full. > (uname is Interix on x86 ver. 3.5) Because the printf() function doesn't write to /dev/full directly. It writes to a stdio buffer associated with the standard output stream. > However, the former is not: according to the ANSI C standard > , =A77.19.6.1/14, > printf should return a negative value in this case. POSIX/SUSv4 (which is aligned with the ISO C standard) says: "If an output error was encountered, these functions shall return a negative value." FreeBSD is compliant with that specification. Note the use of the words "if ... encountered": If the file system is full, that condition is encountered _only_ the next time the stdio library flushes its buffer (which can be as late as the close() call). It is _not_ encountered by the fprintf() function itself, so it is perferctly legal that it does not return a negative value. Best regards Oliver --=20 Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing Dienstleistungen mit Schwerpunkt FreeBSD: http://www.secnetix.de/bsd Any opinions expressed in this message may be personal to the author and may not necessarily reflect the opinions of secnetix in any way. "Emacs ist f=FCr mich kein Editor. F=FCr mich ist das genau das gleiche, = als wenn ich nach einem Fahrrad (f=FCr die Sonntagbr=F6tchen) frage und = einen pangalaktischen Raumkreuzer mit 10 km Gesamtl=E4nge bekomme. Ich wei=DF = nicht, was ich damit soll." -- Frank Klemm, de.comp.os.unix.discussion