From 80abd67f591992ea14440a958fd23e23e71275ec Mon Sep 17 00:00:00 2001 From: tjr Date: Thu, 19 Dec 2002 09:53:26 +0000 Subject: Write the message to stderr, not file descriptor 2, so that perror() writes to the correct stream if stderr has been redirected with freopen(). --- lib/libc/stdio/perror.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/libc') diff --git a/lib/libc/stdio/perror.c b/lib/libc/stdio/perror.c index 162d49e..29016f7 100644 --- a/lib/libc/stdio/perror.c +++ b/lib/libc/stdio/perror.c @@ -46,6 +46,8 @@ __FBSDID("$FreeBSD$"); #include #include #include "un-namespace.h" +#include "libc_private.h" +#include "local.h" void perror(s) @@ -70,5 +72,9 @@ perror(s) v++; v->iov_base = "\n"; v->iov_len = 1; - (void)_writev(STDERR_FILENO, iov, (v - iov) + 1); + FLOCKFILE(stderr); + __sflush(stderr); + (void)_writev(stderr->_file, iov, (v - iov) + 1); + stderr->_flags &= ~__SOFF; + FUNLOCKFILE(stderr); } -- cgit v1.1