This is the mail archive of the newlib@sourceware.org mailing list for the newlib 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: strerror_r questions


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

Attachment: signature.asc
Description: OpenPGP digital signature


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