mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:08:12 +00:00
LibC: Move getsignalbyname() helper from Userland/kill into LibC
This commit is contained in:
parent
a6b2598fba
commit
ad0295d033
3 changed files with 51 additions and 49 deletions
|
@ -30,6 +30,7 @@
|
|||
#include <setjmp.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern "C" {
|
||||
|
@ -186,4 +187,53 @@ int sigsuspend(const sigset_t*)
|
|||
dbgprintf("FIXME: Implement sigsuspend()\n");
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
static const char* signal_names[] = {
|
||||
"INVAL",
|
||||
"HUP",
|
||||
"INT",
|
||||
"QUIT",
|
||||
"ILL",
|
||||
"TRAP",
|
||||
"ABRT",
|
||||
"BUS",
|
||||
"FPE",
|
||||
"KILL",
|
||||
"USR1",
|
||||
"SEGV",
|
||||
"USR2",
|
||||
"PIPE",
|
||||
"ALRM",
|
||||
"TERM",
|
||||
"STKFLT",
|
||||
"CHLD",
|
||||
"CONT",
|
||||
"STOP",
|
||||
"TSTP",
|
||||
"TTIN",
|
||||
"TTOU",
|
||||
"URG",
|
||||
"XCPU",
|
||||
"XFSZ",
|
||||
"VTALRM",
|
||||
"PROF",
|
||||
"WINCH",
|
||||
"IO",
|
||||
"INFO",
|
||||
"SYS",
|
||||
};
|
||||
|
||||
static_assert(sizeof(signal_names) == sizeof(const char*) * 32);
|
||||
|
||||
int getsignalbyname(const char* name)
|
||||
{
|
||||
ASSERT(name);
|
||||
for (size_t i = 0; i < NSIG; ++i) {
|
||||
auto* signal_name = signal_names[i];
|
||||
if (!strcmp(signal_name, name))
|
||||
return i;
|
||||
}
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue