提交 cff4b910 编写于 作者: R Rich Felker

prevent perror from clobbering stderr's orientation

this requirement is specified by POSIX.
上级 cd8d8309
...@@ -10,6 +10,11 @@ void perror(const char *msg) ...@@ -10,6 +10,11 @@ void perror(const char *msg)
FLOCK(f); 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) { if (msg && *msg) {
fwrite(msg, strlen(msg), 1, f); fwrite(msg, strlen(msg), 1, f);
fputc(':', f); fputc(':', f);
...@@ -18,5 +23,8 @@ void perror(const char *msg) ...@@ -18,5 +23,8 @@ void perror(const char *msg)
fwrite(errstr, strlen(errstr), 1, f); fwrite(errstr, strlen(errstr), 1, f);
fputc('\n', f); fputc('\n', f);
f->mode = old_mode;
f->locale = old_locale;
FUNLOCK(f); FUNLOCK(f);
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册