summaryrefslogtreecommitdiff
path: root/lib/libc/signal/sig2str.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/signal/sig2str.c')
-rw-r--r--lib/libc/signal/sig2str.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/libc/signal/sig2str.c b/lib/libc/signal/sig2str.c
new file mode 100644
index 00000000..209cb4c3
--- /dev/null
+++ b/lib/libc/signal/sig2str.c
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include <string.h>
+#include <asm-generic/signal.h>
+#include <__signal.h>
+
+int sig2str(int signum, char *str)
+{
+ if (signum >= SIGHUP && signum <= SIGSYS) {
+ strcpy(str, __sys_signame[signum - SIGHUP]);
+ return 0;
+ }
+
+ if (signum == SIGRTMIN) {
+ strcpy(str, "SIGRTMIN");
+ return 0;
+ }
+
+ if (signum == SIGRTMAX) {
+ strcpy(str, "RTMAX");
+ return 0;
+ }
+
+ if (signum > SIGRTMIN && signum < SIGRTMAX) {
+ if (signum - SIGRTMIN <= SIGRTMAX - signum) {
+ sprintf(str, "RTMIN+%d", signum - SIGRTMIN);
+ } else {
+ sprintf(str, "RTMAX-%d", SIGRTMAX - signum);
+ }
+ return 0;
+ }
+
+ return -1;
+}