strerror_r questions
Eric Blake
eblake@redhat.com
Thu Feb 10 00:17:00 GMT 2011
On 02/09/2011 03:43 PM, Eric Blake wrote:
>>> - return strncpy (buffer, (const char *)error, n);
>>> + strncpy (buffer, error, n);
>>> + return strlen (error) >= n ? error : buffer;
>>
>> This looks wrong to me. Glibc guarantees that the copied result in
>> buffer is NUL-terminated, and I'm missing the "Unknown error XXX"
>> message.
>
> No. I strongly feel that strerror and strerror_r should return the same
> strings (insofar as possible).
Oh, and I just re-read the glibc man page:
The GNU-specific strerror_r() returns a pointer to a string
containing
the error message. This may be either a pointer to a string
that the
function stores in buf, or a pointer to some (immutable) static
string
(in which case buf is unused). If the function stores a string
in buf,
then at most buflen bytes are stored (the string may be
truncated if
buflen is too small) and the string always includes a
terminating null
byte.
That is, my implementation was wrong, and buf should be left untouched
if it is not the return value. Will fix in v2.
--
Eric Blake eblake@redhat.com +1-801-349-2682
Libvirt virtualization library http://libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://sourceware.org/pipermail/newlib/attachments/20110210/9767ed20/attachment.sig>
More information about the Newlib
mailing list