This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: vsnprintf


Bob Koninckx wrote:
Seems like vsnprintf _always_ returns the number of bytes actually
written, also if the provided buffer was too small, in which case the
number of bytes that would have been written if a large enough buffer
would have been available should be returned.

Anyone else seen this ? Did I miss something ?
I believe the behaviour you want is new in C99 (certainly new as far as the eCos C library is concerned :-)). Or rather, C99 added the *nprintf functions (vsnprintf and snprintf). This was to reflect existing practice, like we have in eCos, except that they defined the return value differently from that existing practice.

For example, the glibc manpage for vsnprintf says:
-=-=-=-=-
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. (Thus until glibc 2.0.6. Since glibc 2.1 these functions follow the C99 standard and return the number of characters (excluding the trailing '\0') which would have been written to the final string if enough space had been available.)
-=-=-=-=-

It's their choice since those functions weren't defined officially earlier.

For now, we've ignored the issue :-). We're not C99 compliant in so many other ways anyway.

Jifl
--
eCosCentric http://www.eCosCentric.com/ <info@eCosCentric.com>
--[ "You can complain because roses have thorns, or you ]--
--[ can rejoice because thorns have roses." -Lincoln ]-- Opinions==mine


--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]