From 0b44a0315b47dd8eced9f3b7f31580cf14bbfc01 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 12 Feb 2011 00:22:29 -0500 Subject: initial check-in, version 0.5.0 --- src/stdio/perror.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/stdio/perror.c (limited to 'src/stdio/perror.c') diff --git a/src/stdio/perror.c b/src/stdio/perror.c new file mode 100644 index 00000000..e4637c8a --- /dev/null +++ b/src/stdio/perror.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include "stdio_impl.h" + +void perror(const char *msg) +{ +#if 1 + if (msg) fprintf(stderr, "%s: %m\n", msg, strerror(errno)); + else fprintf(stderr, "%m\n"); +#else + FILE *f = stderr; + char *errstr = strerror(errno); + + FLOCK(f); + + if (msg) { + __fwritex(msg, strlen(msg), f); + __putc_unlocked(':', f); + __putc_unlocked(' ', f); + } + __fwritex(errstr, strlen(errstr), f); + __putc_unlocked('\n', f); + + FUNLOCK(f); +#endif +} -- cgit v1.2.1