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] |
On 02/10/2011 09:16 AM, Eric Blake wrote: >> That's not how I understand the sentence >> >> 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. > > Glibc documentation is ambiguous - first it states that if n is too > small, then buf is not modified nor returned; then it states that if n > is too small, buf gets a truncated string. An actual test program > proves the point: > > $ cat foo.c > #define _GNU_SOURCE 1 > #include <stdio.h> > #include <string.h> > #include <errno.h> > int main (void) { > char buf[80] = "Hello world"; > char *p = strerror_r (1, buf, 4); > printf ("buf=%s\np=%s\n", buf, p); > return 0; > } > $ ./foo > buf=Hello world > p=Operation not permitted > > I'll be submitting a bug report to the Linux man-pages project. Or not; change 1 to -1 in the above program, and the output becomes: buf=Unk p=Unk That is, glibc's formatting of "Unknown error -1" is done into the provided buffer, and not into temporary thread-safe storage, and is indeed truncated in that case. -- 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] |