libc: strsignal

This commit is contained in:
K. Lange 2022-08-18 19:20:56 +09:00
parent 5aa2b32101
commit 908dbb0553
3 changed files with 58 additions and 1 deletions

View File

@ -52,6 +52,9 @@ extern char * strncpy(char *dest, const char *src, size_t n);
extern char * strerror(int errnum);
extern size_t strxfrm(char *dest, const char *src, size_t n);
extern char * strsignal(int sign);
extern const char * const sys_siglist[];
_End_C_Header
#include <strings.h>

View File

@ -37,7 +37,6 @@
#define SIGHATE 34 /* The sending process does not like you */
#define SIGWINEVENT 35 /* Window server event */
#define SIGCAT 36 /* Everybody loves cats */
#define SIGTTOU 37
#define NUMSIGNALS 38

55
libc/string/strsignal.c Normal file
View File

@ -0,0 +1,55 @@
#include <string.h>
#include <signal.h>
#include <stdio.h>
const char * const sys_siglist[] = {
[SIGHUP] = "Hangup",
[SIGINT] = "Interrupt",
[SIGQUIT] = "Quit",
[SIGILL] = "Illegal instruction",
[SIGTRAP] = "Trace/breakpoint trap",
[SIGABRT] = "Aborted",
[SIGEMT] = "Emulation trap",
[SIGFPE] = "Arithmetic exception",
[SIGKILL] = "Killed",
[SIGBUS] = "Bus error",
[SIGSEGV] = "Segmentation fault",
[SIGSYS] = "Bad system call",
[SIGPIPE] = "Broken pipe",
[SIGALRM] = "Alarm clock",
[SIGTERM] = "Terminated",
[SIGUSR1] = "User defined signal 1",
[SIGUSR2] = "User defined signal 2",
[SIGCHLD] = "Child process status",
[SIGPWR] = "Power failure",
[SIGWINCH] = "Window changed",
[SIGURG] = "Urgent I/O condition",
[SIGPOLL] = "Pollable event",
[SIGSTOP] = "Stopped",
[SIGTSTP] = "Stopped",
[SIGCONT] = "Continued",
[SIGTTIN] = "Stopped (tty input)",
[SIGTTOU] = "Stopped (tty output)",
[SIGTTOUT] = "Stopped (tty output)",
[SIGVTALRM] = "Virtual timer expired",
[SIGPROF] = "Profiling timer expired",
[SIGXCPU] = "CPU time limit exceeded",
[SIGXFSZ] = "File size limit exceeded",
/* silly stuff */
[SIGWAITING] = "Waiting",
[SIGDIAF] = "Died in a fire",
[SIGHATE] = "Hated",
[SIGWINEVENT] = "Window event",
[SIGCAT] = "Meow",
};
char * strsignal(int sig) {
static char _signal_description[256];
if (sig > 0 && sig < NUMSIGNALS) {
snprintf(_signal_description, 256, "%s", sys_siglist[sig]);
} else {
snprintf(_signal_description, 256, "Killed by signal %d", sig);
}
return _signal_description;
}