projects
/
oweals
/
musl.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
cd8d830
)
prevent perror from clobbering stderr's orientation
author
Rich Felker
<dalias@aerifal.cx>
Thu, 30 Aug 2018 04:08:16 +0000
(
00:08
-0400)
committer
Rich Felker
<dalias@aerifal.cx>
Thu, 30 Aug 2018 04:08:16 +0000
(
00:08
-0400)
this requirement is specified by POSIX.
src/stdio/perror.c
patch
|
blob
|
history
diff --git
a/src/stdio/perror.c
b/src/stdio/perror.c
index fdcb4d71c8855201c8a67858e8fa607fff038744..d0943f26a938bd9dad153c1d64dd88f643c31097 100644
(file)
--- a/
src/stdio/perror.c
+++ b/
src/stdio/perror.c
@@
-9,6
+9,11
@@
void perror(const char *msg)
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);
@@
-18,5
+23,8
@@
void perror(const char *msg)
fwrite(errstr, strlen(errstr), 1, f);
fputc('\n', f);
+ f->mode = old_mode;
+ f->locale = old_locale;
+
FUNLOCK(f);
}