Subject: Query about return value of snprintf
To: None <email@example.com>
From: None <firstname.lastname@example.org>
Date: 06/17/1999 17:02:11
-----BEGIN PGP SIGNED MESSAGE-----
The NetBSD man page says that we do:
These functions return the number of characters printed (not including
the trailing `\0' used to end output to strings).
Which is what I expected.
The GNU glibc man page (on RedHat 6.0 Linux from man-pages-1.17-1, but
also for the 6.0 release of man-pages-1.23-3) for snprintf says:
If the output was truncated, the return value is -1, oth-
erwise it is the number of characters stored, not includ-
ing the terminating null.
and the one for printf(3) (don't ask me why there are two pages)
These functions return the number of characters printed
(not including the trailing `\0' used to end output to
strings). snprintf and vsnprintf do not write more than
size bytes (including the trailing '\0'), and return -1 if
the output was truncated due to this limit.
I do have any code that cares one way or another. I also have a portable
snprintf() that I use on NT and Slowlaris and it makes some of my regression
tests a pain in the butt since I prefer to use the OS resident one.
I realize that this isn't POSIX, but are there any opinions as what is
reasonable? I see reasons why the GNU version is useful, but I also see that
it may break existing code.
:!mcr!: | Network and security consulting/contract programming
Michael Richardson | ...working from my front lawn with a long cord...
ON HUMILITY: To err is human, to moo bovine.
-----BEGIN PGP SIGNATURE-----
Comment: Processed by Mailcrypt 3.4, an Emacs/PGP interface
-----END PGP SIGNATURE-----