This is the mail archive of the
ecos-patches@sourceware.org
mailing list for the eCos project.
Re: _vprintf() return code fix and diag_vsnprintf() addition
- From: Andrew Lunn <andrew at lunn dot ch>
- To: Berend Ozceri <berend at eye dot fi>
- Cc: ecos-patches at sourceware dot org
- Date: Mon, 3 Nov 2008 15:50:56 +0100
- Subject: Re: _vprintf() return code fix and diag_vsnprintf() addition
- References: <60567D22-14DE-43B4-8ACF-E62A69C6BBD1@eye.fi>
On Mon, Oct 20, 2008 at 07:32:19PM -0700, Berend Ozceri wrote:
> This fixes a return value error in _vprintf() (if _sputc() clips the
> output due to the maximum output buffer length being reached)
Could you explain this a bit more. Which functions are returning the
wrong value?
The man page for vprintf says this:
Upon successful return, these functions return the number of
characters printed (not including the trailing '\0' used to end
output to strings).
The functions snprintf() and vsnprintf() do not write more than
size bytes (including the trailing '\0'). If the output was
truncated due to this limit then the return value is the
number of characters (not including the trailing '\0') which
would have been written to the final string if enough space had
been available. Thus, a return value of size or more means
that the output was truncated.
My understanding of the eCos code is that the current _vprintf()
function returns the unrestricted number of characters. info->len is
the number of characters actually output, which may of been truncated.
It seems to me diag_vsprintf(), diag_snprintf() and diag_sprintf() are
wrong. These all return info.len when they should return the return
value from _vprintf().
Would you agree?
Thanks
Andrew