LibC: Fix strsignal() and implement psignal()

This commit is contained in:
Bananymous 2024-08-05 00:59:03 +03:00
parent a749b9806e
commit adadb10b15
2 changed files with 37 additions and 28 deletions

View File

@ -1,5 +1,6 @@
#include <BAN/Assert.h>
#include <signal.h>
#include <string.h>
#include <sys/syscall.h>
#include <unistd.h>
@ -10,6 +11,14 @@ int kill(pid_t pid, int sig)
return syscall(SYS_KILL, pid, sig);
}
void psignal(int signum, const char* message)
{
if (message && *message)
fprintf(stderr, "%s: %s\n", message, strsignal(signum));
else
fprintf(stderr, "%s\n", strsignal(signum));
}
int raise(int sig)
{
// FIXME: won't work after multithreaded

View File

@ -317,34 +317,34 @@ char* strsignal(int signum)
static char buffer[128];
switch (signum)
{
case SIGABRT: strcpy(buffer, "SIGABRT"); break;
case SIGALRM: strcpy(buffer, "SIGALRM"); break;
case SIGBUS: strcpy(buffer, "SIGBUS"); break;
case SIGCHLD: strcpy(buffer, "SIGCHLD"); break;
case SIGCONT: strcpy(buffer, "SIGCONT"); break;
case SIGFPE: strcpy(buffer, "SIGFPE"); break;
case SIGHUP: strcpy(buffer, "SIGHUP"); break;
case SIGILL: strcpy(buffer, "SIGILL"); break;
case SIGINT: strcpy(buffer, "SIGINT"); break;
case SIGKILL: strcpy(buffer, "SIGKILL"); break;
case SIGPIPE: strcpy(buffer, "SIGPIPE"); break;
case SIGQUIT: strcpy(buffer, "SIGQUIT"); break;
case SIGSEGV: strcpy(buffer, "SIGSEGV"); break;
case SIGSTOP: strcpy(buffer, "SIGSTOP"); break;
case SIGTERM: strcpy(buffer, "SIGTERM"); break;
case SIGTSTP: strcpy(buffer, "SIGTSTP"); break;
case SIGTTIN: strcpy(buffer, "SIGTTIN"); break;
case SIGTTOU: strcpy(buffer, "SIGTTOU"); break;
case SIGUSR1: strcpy(buffer, "SIGUSR1"); break;
case SIGUSR2: strcpy(buffer, "SIGUSR2"); break;
case SIGPOLL: strcpy(buffer, "SIGPOLL"); break;
case SIGPROF: strcpy(buffer, "SIGPROF"); break;
case SIGSYS: strcpy(buffer, "SIGSYS"); break;
case SIGTRAP: strcpy(buffer, "SIGTRAP"); break;
case SIGURG: strcpy(buffer, "SIGURG"); break;
case SIGVTALRM: strcpy(buffer, "SIGVTALRM"); break;
case SIGXCPU: strcpy(buffer, "SIGXCPU"); break;
case SIGXFSZ: strcpy(buffer, "SIGXFSZ"); break;
case SIGABRT: strcpy(buffer, "Process abort signal."); break;
case SIGALRM: strcpy(buffer, "Alarm clock."); break;
case SIGBUS: strcpy(buffer, "Access to an undefined portion of a memory object."); break;
case SIGCHLD: strcpy(buffer, "Child process terminated, stopped, or continued."); break;
case SIGCONT: strcpy(buffer, "Continue executing, if stopped."); break;
case SIGFPE: strcpy(buffer, "Erroneous arithmetic operation."); break;
case SIGHUP: strcpy(buffer, "Hangup."); break;
case SIGILL: strcpy(buffer, "Illegal instruction."); break;
case SIGINT: strcpy(buffer, "Terminal interrupt signal."); break;
case SIGKILL: strcpy(buffer, "Kill (cannot be caught or ignored)."); break;
case SIGPIPE: strcpy(buffer, "Write on a pipe with no one to read it."); break;
case SIGQUIT: strcpy(buffer, "Terminal quit signal."); break;
case SIGSEGV: strcpy(buffer, "Invalid memory reference."); break;
case SIGSTOP: strcpy(buffer, "Stop executing (cannot be caught or ignored)."); break;
case SIGTERM: strcpy(buffer, "Termination signal."); break;
case SIGTSTP: strcpy(buffer, "Terminal stop signal."); break;
case SIGTTIN: strcpy(buffer, "Background process attempting read."); break;
case SIGTTOU: strcpy(buffer, "Background process attempting write."); break;
case SIGUSR1: strcpy(buffer, "User-defined signal 1."); break;
case SIGUSR2: strcpy(buffer, "User-defined signal 2."); break;
case SIGPOLL: strcpy(buffer, "Pollable event."); break;
case SIGPROF: strcpy(buffer, "Profiling timer expired."); break;
case SIGSYS: strcpy(buffer, "Bad system call."); break;
case SIGTRAP: strcpy(buffer, "Trace/breakpoint trap."); break;
case SIGURG: strcpy(buffer, "High bandwidth data is available at a socket."); break;
case SIGVTALRM: strcpy(buffer, "Virtual timer expired."); break;
case SIGXCPU: strcpy(buffer, "CPU time limit exceeded."); break;
case SIGXFSZ: strcpy(buffer, "File size limit exceeded."); break;
}
return buffer;
}