aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTim J. Robbins <tjr@FreeBSD.org>2002-12-19 09:53:26 +0000
committerTim J. Robbins <tjr@FreeBSD.org>2002-12-19 09:53:26 +0000
commit37d2356335dc49410c518879de3bef3c5cf298ec (patch)
treebc7f0601bf214c5e63115618af3226ea6224f612 /lib
parenta207a8e3f157060bb6dcc338b895da3b44bfad85 (diff)
Write the message to stderr, not file descriptor 2, so that perror()
writes to the correct stream if stderr has been redirected with freopen().
Notes
Notes: svn path=/head/; revision=108090
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/stdio/perror.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/libc/stdio/perror.c b/lib/libc/stdio/perror.c
index 162d49e56d1c..29016f742444 100644
--- a/lib/libc/stdio/perror.c
+++ b/lib/libc/stdio/perror.c
@@ -46,6 +46,8 @@ __FBSDID("$FreeBSD$");
#include <stdio.h>
#include <string.h>
#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);
}