summaryrefslogtreecommitdiff
path: root/lib/strerror.c
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2011-05-19 21:49:01 +0200
committerBruno Haible <bruno@clisp.org>2011-05-19 21:49:01 +0200
commit30f176b6e12f1a67070991ee7ac505f2fa8a605c (patch)
treef2dbb7e3407b9365ff218a86524e637299892b0b /lib/strerror.c
parentb79d34835799d78d05b99916bfc363850905601c (diff)
downloadgnulib-30f176b6e12f1a67070991ee7ac505f2fa8a605c.tar.gz
perror: Avoid clobbering the strerror buffer when possible.
* lib/strerror-impl.h: New file, extracted from lib/strerror.c. * lib/strerror.c: Include it. * modules/strerror (Files): Add lib/strerror-impl.h. * lib/perror.c: Include <stdlib.h>, intprops.h, verify.h. (my_strerror): New function, defined through lib/strerror-impl.h. (perror): Use it instead of strerror. * modules/perror (Files): Add lib/strerror-impl.h. (Depends-on): Remove strerror. Add intprops, verify, strerror_r-posix.
Diffstat (limited to 'lib/strerror.c')
-rw-r--r--lib/strerror.c22
1 files changed, 1 insertions, 21 deletions
diff --git a/lib/strerror.c b/lib/strerror.c
index 6137552efd..f0e03df95d 100644
--- a/lib/strerror.c
+++ b/lib/strerror.c
@@ -32,26 +32,6 @@
/* Use the system functions, not the gnulib overrides in this file. */
# undef sprintf
-char *
-strerror (int n)
-{
- static char buf[256];
-
- int ret = strerror_r (n, buf, sizeof (buf));
-
- if (ret == 0)
- return buf;
-
- if (ret == ERANGE)
- /* If this happens, increase the size of buf. */
- abort ();
-
- {
- static char const fmt[] = "Unknown error (%d)";
- verify (sizeof (buf) >= sizeof (fmt) + INT_STRLEN_BOUND (n));
- sprintf (buf, fmt, n);
- return buf;
- }
-}
+# include "strerror-impl.h"
#endif