Subject: Re: Query about return value of snprintf
To: Chris G. Demetriou <email@example.com>
From: Andreas Jaeger <firstname.lastname@example.org>
Date: 06/18/1999 00:14:45
>>>>> Chris G Demetriou writes:
Chris> email@example.com writes:
>> 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.
Chris> No, that's part of what it says.
Chris> Further it says:
Chris> snprintf() and vsnprintf() will write at most size-1 of the characters
Chris> printed into the output string (the size'th character then gets the ter-
Chris> minating `\0'); if the return value is greater than or equal to the size
Chris> argument, the string was too short and some of the printed characters
Chris> were discarded.
Chris> i.e. it actually returns the number of characters that would have been
Chris> printed, given an adequately-sided buffer.
>> RETURN VALUE
>> 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.
Chris> I consider the BSD behaviour much preferred to what you quote as the
Chris> GNU libc behaviour.
I agree. And since ISO C9x specifies this behaviour also, glibc has
been changed (see my other email).
Andreas Jaeger firstname.lastname@example.org email@example.com
for pgp-key finger firstname.lastname@example.org