• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <stdio.h>
2 #include <string.h>
3 #include <errno.h>
4 #include "stdio_impl.h"
5 
perror(const char * msg)6 void perror(const char *msg)
7 {
8 	FILE *f = stderr;
9 	char *errstr = strerror(errno);
10 
11 	FLOCK(f);
12 
13 	/* Save stderr's orientation and encoding rule, since perror is not
14 	 * permitted to change them. */
15 	void *old_locale = f->locale;
16 	int old_mode = f->mode;
17 
18 	if (msg && *msg) {
19 		fwrite(msg, strlen(msg), 1, f);
20 		fputc(':', f);
21 		fputc(' ', f);
22 	}
23 	fwrite(errstr, strlen(errstr), 1, f);
24 	fputc('\n', f);
25 
26 	f->mode = old_mode;
27 	f->locale = old_locale;
28 
29 	FUNLOCK(f);
30 }
31