From a207a8e3f157060bb6dcc338b895da3b44bfad85 Mon Sep 17 00:00:00 2001 From: "Tim J. Robbins" Date: Thu, 19 Dec 2002 09:50:10 +0000 Subject: [PATCH] Use strerror_r() to format the error message so that strerror()'s static buffer does not get clobbered. ISO/IEC 9899:1999 7.21.6.2 3: "The implementation shall behave as if no library function calls the strerror function." --- lib/libc/stdio/perror.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/libc/stdio/perror.c b/lib/libc/stdio/perror.c index 226c1897bf8..162d49e56d1 100644 --- a/lib/libc/stdio/perror.c +++ b/lib/libc/stdio/perror.c @@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include "un-namespace.h" @@ -50,6 +51,7 @@ void perror(s) const char *s; { + char msgbuf[NL_TEXTMAX]; struct iovec *v; struct iovec iov[4]; @@ -62,7 +64,8 @@ perror(s) v->iov_len = 2; v++; } - v->iov_base = strerror(errno); + strerror_r(errno, msgbuf, sizeof(msgbuf)); + v->iov_base = msgbuf; v->iov_len = strlen(v->iov_base); v++; v->iov_base = "\n";