summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/perror.c
diff options
context:
space:
mode:
authorespie <espie@openbsd.org>2004-05-03 05:07:34 +0000
committerespie <espie@openbsd.org>2004-05-03 05:07:34 +0000
commit232b982ab46ea31ecbfd773dded4d52b5c506d17 (patch)
treea3be37b60adb5df676f43dfaba58a7c934a9ba6b /lib/libc/stdio/perror.c
parentlittle KNF issue (diff)
downloadwireguard-openbsd-232b982ab46ea31ecbfd773dded4d52b5c506d17.tar.xz
wireguard-openbsd-232b982ab46ea31ecbfd773dded4d52b5c506d17.zip
build the error message in strerror_r.c directly, avoiding one copy there.
handle a few subtle details caught by the regression tests: correct termination, non copying if buffer length == 0, errno setting. let all former users of __strerror go through strerror_r. Work by Todd Miller and I. Okay millert@.
Diffstat (limited to 'lib/libc/stdio/perror.c')
-rw-r--r--lib/libc/stdio/perror.c12
1 files changed, 3 insertions, 9 deletions
diff --git a/lib/libc/stdio/perror.c b/lib/libc/stdio/perror.c
index 68ab7f41151..b5e855014a6 100644
--- a/lib/libc/stdio/perror.c
+++ b/lib/libc/stdio/perror.c
@@ -28,7 +28,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: perror.c,v 1.5 2003/06/02 20:18:37 millert Exp $";
+static char rcsid[] = "$OpenBSD: perror.c,v 1.6 2004/05/03 05:07:34 espie Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -38,13 +38,6 @@ static char rcsid[] = "$OpenBSD: perror.c,v 1.5 2003/06/02 20:18:37 millert Exp
#include <stdio.h>
#include <string.h>
#include <limits.h>
-/*
- * Since perror() is not allowed to change the contents of strerror()'s
- * static buffer, both functions supply their own buffers to the
- * internal function __strerror().
- */
-
-extern char *__strerror(int , char *);
void
perror(s)
@@ -63,7 +56,8 @@ perror(s)
v->iov_len = 2;
v++;
}
- v->iov_base = __strerror(errno, buf);
+ (void)strerror_r(errno, buf, sizeof(buf));
+ v->iov_base = buf;
v->iov_len = strlen(v->iov_base);
v++;
v->iov_base = "\n";