Date: Tue, 23 Jan 2007 11:29:13 +0100 From: =?iso-8859-2?Q?K=F8i=B9tof_=AEelechovski?= <giecrilj@stegny.2a.pl> To: <freebsd-standards@FreeBSD.ORG>, <giecrilj@stegny.2a.pl> Subject: RE: return value of fprintf Message-ID: <000401c73ed9$540afca0$1a01080a@POCZTOWIEC> In-Reply-To: <200701230759.l0N7xCdg002571@lurza.secnetix.de> References: <005301c73e6c$ba6ffd00$1a01080a@POCZTOWIEC> <200701230759.l0N7xCdg002571@lurza.secnetix.de>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <giecrilj@stegny.2a.pl> wrote: > The > <http://www.freebsd.org/cgi/man.cgi?query=3Dfprintf&apropos=3D0&sektion=3D= 0&manpat > 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 > <http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1124.pdf> , =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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?000401c73ed9$540afca0$1a01080a>