strerror_r: guarantee unchanged errno
authorEric Blake <eblake@redhat.com>
Thu, 19 May 2011 19:35:39 +0000 (13:35 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 19 May 2011 20:53:05 +0000 (14:53 -0600)
commit7f4877b4ad7eade913808e4b7a412e30be632bab
treefccb17add65c55f3f35bd223a7a57e2e7326bddb
parente18f296f3ec35d260b38eca33621224dc674fd3d
strerror_r: guarantee unchanged errno

POSIX guarantees that strerror doesn't change errno on success,
and since we implement strerror by using strerror_r, it makes
sense to make the same guarantee for strerror_r (rather, going
one step further to say that sterror_r does not corrupt errno,
since it returns an error value explicitly).

See also http://austingroupbugs.net/view.php?id=447

* lib/strerror_r.c (strerror_r): Guarantee unchanged errno.
* lib/strerror-impl.h (strerror): Set errno to match strerror_r
failure.
* tests/test-strerror_r.c (main): Enhance test.

Signed-off-by: Eric Blake <eblake@redhat.com>
ChangeLog
lib/strerror-impl.h
lib/strerror_r.c
tests/test-strerror_r.c