Debian Codegraph @

libc-top-half/musl/src/signal/psignal.c

raw
1 #include "stdio_impl.h"
2 #include <string.h>
3 #include <signal.h>
4 #include <errno.h>
5
6 #ifndef __wasilibc_unmodified_upstream
7 /* undef the macro to use the standard stderr instead of __stderr_FILE
8 * (the libc internal symbol) as this lives in a separate library,
9 * libwasi-emulated-signal.so. */
10 #undef stderr
11 #endif
12
13 void psignal(int sig, const char *msg)
14 {
15 FILE *f = stderr;
16 char *s = strsignal(sig);
17
18 FLOCK(f);
19
20 /* Save stderr's orientation and encoding rule, since psignal is not
21 * permitted to change them. Save errno and restore it if there is no
22 * error since fprintf might change it even on success but psignal is
23 * not permitted to do so. */
24 void *old_locale = f->locale;
25 int old_mode = f->mode;
26 int old_errno = errno;
27
28 if (fprintf(f, "%s%s%s\n", msg?msg:"", msg?": ":"", s)>=0)
29 errno = old_errno;
30 f->mode = old_mode;
31 f->locale = old_locale;
32
33 FUNLOCK(f);
34 }