mirror of
git://git.musl-libc.org/musl
synced 2025-03-06 20:48:29 +01:00
prevent perror from clobbering stderr's orientation
this requirement is specified by POSIX.
This commit is contained in:
parent
cd8d830997
commit
cff4b910ab
1 changed files with 8 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue