Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Jan 2007 08:59:12 +0100 (CET)
From:      Oliver Fromme <olli@lurza.secnetix.de>
To:        freebsd-standards@FreeBSD.ORG, giecrilj@stegny.2a.pl
Subject:   Re: return value of fprintf
Message-ID:  <200701230759.l0N7xCdg002571@lurza.secnetix.de>
In-Reply-To: <005301c73e6c$ba6ffd00$1a01080a@POCZTOWIEC>

next in thread | previous in thread | raw e-mail | index | archive | help
K?i?tof ?elechovski <giecrilj@stegny.2a.pl> wrote:
 > The
 > <http://www.freebsd.org/cgi/man.cgi?query=fprintf&apropos=0&sektion=0&manpat
 > h=FreeBSD+7-current&format=html> fprintf manual page says it is ANSI C
 > compatible and it returns the number of characters printed.
 > 
 > The latter is correct: I get printf("abcd") == 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>; , §7.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

-- 
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ür mich kein Editor. Für mich ist das genau das gleiche, als
wenn ich nach einem Fahrrad (für die Sonntagbrötchen) frage und einen
pangalaktischen Raumkreuzer mit 10 km Gesamtlänge bekomme. Ich weiß 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?200701230759.l0N7xCdg002571>