2007-09-05

Pitfall of strerror_r() of GNU libc

int strerror_r(int errnum, char *buf, size_t n);

CONFORMING TO: SVID 3, POSIX, 4.3BSD, ISO/IEC 9899:1990 (C89).

strerror_r() with prototype as given above is specified by SUSv3, and was in use under Digital Unix and HP Unix. An incompatible function, with prototype

char *strerror_r(int errnum, char *buf, size_t n);

is a GNU extension used by glibc (since 2.0), and must be regarded as obsolete in view of SUSv3. The GNU version may, but need not, use the user-supplied buffer. If it does, the result may be truncated in case the supplied buffer is too small. The result is always NUL-terminated.

No comments: