1570af302Sopenharmony_ci#include <stdio.h> 2570af302Sopenharmony_ci#include <string.h> 3570af302Sopenharmony_ci#include <errno.h> 4570af302Sopenharmony_ci#include "stdio_impl.h" 5570af302Sopenharmony_ci 6570af302Sopenharmony_civoid perror(const char *msg) 7570af302Sopenharmony_ci{ 8570af302Sopenharmony_ci FILE *f = stderr; 9570af302Sopenharmony_ci char *errstr = strerror(errno); 10570af302Sopenharmony_ci 11570af302Sopenharmony_ci FLOCK(f); 12570af302Sopenharmony_ci 13570af302Sopenharmony_ci /* Save stderr's orientation and encoding rule, since perror is not 14570af302Sopenharmony_ci * permitted to change them. */ 15570af302Sopenharmony_ci void *old_locale = f->locale; 16570af302Sopenharmony_ci int old_mode = f->mode; 17570af302Sopenharmony_ci 18570af302Sopenharmony_ci if (msg && *msg) { 19570af302Sopenharmony_ci fwrite(msg, strlen(msg), 1, f); 20570af302Sopenharmony_ci fputc(':', f); 21570af302Sopenharmony_ci fputc(' ', f); 22570af302Sopenharmony_ci } 23570af302Sopenharmony_ci fwrite(errstr, strlen(errstr), 1, f); 24570af302Sopenharmony_ci fputc('\n', f); 25570af302Sopenharmony_ci 26570af302Sopenharmony_ci f->mode = old_mode; 27570af302Sopenharmony_ci f->locale = old_locale; 28570af302Sopenharmony_ci 29570af302Sopenharmony_ci FUNLOCK(f); 30570af302Sopenharmony_ci} 31