summaryrefslogtreecommitdiffstats
path: root/libc-top-half/musl/src/stdio/perror.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc-top-half/musl/src/stdio/perror.c')
-rw-r--r--libc-top-half/musl/src/stdio/perror.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/libc-top-half/musl/src/stdio/perror.c b/libc-top-half/musl/src/stdio/perror.c
new file mode 100644
index 0000000..d0943f2
--- /dev/null
+++ b/libc-top-half/musl/src/stdio/perror.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include "stdio_impl.h"
+
+void perror(const char *msg)
+{
+ FILE *f = stderr;
+ char *errstr = strerror(errno);
+
+ FLOCK(f);
+
+ /* Save stderr's orientation and encoding rule, since perror is not
+ * permitted to change them. */
+ void *old_locale = f->locale;
+ int old_mode = f->mode;
+
+ if (msg && *msg) {
+ fwrite(msg, strlen(msg), 1, f);
+ fputc(':', f);
+ fputc(' ', f);
+ }
+ fwrite(errstr, strlen(errstr), 1, f);
+ fputc('\n', f);
+
+ f->mode = old_mode;
+ f->locale = old_locale;
+
+ FUNLOCK(f);
+}