[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/2] strerror: work around FreeBSD bug
From: |
Eric Blake |
Subject: |
[PATCH 2/2] strerror: work around FreeBSD bug |
Date: |
Mon, 6 Jun 2011 15:40:16 -0600 |
Breaking strerror away from strerror_r re-exposed the FreeBSD
strerror(0) bug.
* lib/strerror.c (strerror): Special case 0.
Reported by Bruno Haible.
Signed-off-by: Eric Blake <address@hidden>
---
This fixes test-strerror on FreeBSD, again.
I still need to work on perror, but I'm pushing this in the meantime.
ChangeLog | 4 ++++
lib/strerror.c | 14 +++++++++++++-
2 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 363ee1f..35497d0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2011-06-06 Eric Blake <address@hidden>
+ strerror: work around FreeBSD bug
+ * lib/strerror.c (strerror): Special case 0.
+ Reported by Bruno Haible.
+
strerror-override: avoid bloating errno module
* modules/errno (Files, configure.ac): Move replacement strings...
* modules/strerror-override: ...to new module.
diff --git a/lib/strerror.c b/lib/strerror.c
index 8c41179..4dc0b65 100644
--- a/lib/strerror.c
+++ b/lib/strerror.c
@@ -45,10 +45,22 @@ strerror (int n)
if (msg)
return (char *) msg;
+ /* FreeBSD rejects 0; see http://austingroupbugs.net/view.php?id=382. */
+ if (n)
+ msg = strerror (n);
+ else
+ {
+ int saved_errno = errno;
+ errno = 0;
+ msg = strerror (n);
+ if (errno)
+ msg = "Success";
+ errno = saved_errno;
+ }
+
/* Our strerror_r implementation might use the system's strerror
buffer, so all other clients of strerror have to see the error
copied into a buffer that we manage. */
- msg = strerror (n);
if (!msg || !*msg)
{
static char const fmt[] = "Unknown error %d";
--
1.7.4.4
- [PATCHv2] strerror: drop strerror_r dependency, Eric Blake, 2011/06/01
- Re: [PATCHv2] strerror: drop strerror_r dependency, Bruno Haible, 2011/06/03
- [PATCH 1/2] strerror-override: avoid bloating errno module, Eric Blake, 2011/06/06
- [PATCH 2/2] strerror: work around FreeBSD bug,
Eric Blake <=
- Re: [PATCH 2/2] strerror: work around FreeBSD bug, Bruno Haible, 2011/06/07
- Re: [PATCH 2/2] strerror: work around FreeBSD bug, Eric Blake, 2011/06/07
- Re: [PATCH 2/2] strerror: work around FreeBSD bug, Eric Blake, 2011/06/07
- MacOS strerror_r [was: [PATCH 2/2] strerror: work around FreeBSD bug], Eric Blake, 2011/06/08
- Re: MacOS strerror_r, Eric Blake, 2011/06/08
- Re: [PATCH 2/2] strerror: work around FreeBSD bug, Eric Blake, 2011/06/08
Re: [PATCHv2] strerror: drop strerror_r dependency, Bruno Haible, 2011/06/04