|
|
Message-ID: <20240805065607.22897-2-contact@hacktivis.me>
Date: Mon, 5 Aug 2024 08:56:06 +0200
From: contact@...ktivis.me
To: musl@...ts.openwall.com
Cc: "Haelwenn (lanodan) Monnier" <contact@...ktivis.me>
Subject: [PATCH v2 2/3] signal: add sig2str(3) from POSIX.1-2024
From: "Haelwenn (lanodan) Monnier" <contact@...ktivis.me>
---
include/signal.h | 3 +++
src/signal/sig2str.c | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+)
create mode 100644 src/signal/sig2str.c
diff --git a/include/signal.h b/include/signal.h
index c347f861..217cfa08 100644
--- a/include/signal.h
+++ b/include/signal.h
@@ -233,6 +233,9 @@ int pthread_kill(pthread_t, int);
void psiginfo(const siginfo_t *, const char *);
void psignal(int, const char *);
+#define SIG2STR_MAX sizeof("RTMIN+32")
+int sig2str(int signum, char *str);
+
#endif
#if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
diff --git a/src/signal/sig2str.c b/src/signal/sig2str.c
new file mode 100644
index 00000000..1967159c
--- /dev/null
+++ b/src/signal/sig2str.c
@@ -0,0 +1,42 @@
+#include <signal.h>
+#include <string.h>
+
+int sig2str(int sig, char *str)
+{
+ if (sig <= 0) return -1;
+
+ if (sig <= SIGSYS)
+ return (strcpy(str, __sys_signame[sig]), 0);
+
+ if (sig == SIGRTMIN)
+ return (strcpy(str, "RTMIN"), 0);
+ if (sig == SIGRTMAX)
+ return (strcpy(str, "RTMAX"), 0);
+
+#if SIGPOLL != SIGIO
+ if (sig == SIGPOLL)
+ return (strcpy(str, "POLL"), 0);
+#endif
+
+ if (sig > SIGRTMIN && sig <= SIGRTMAX)
+ {
+ strcpy(str, "RTMIN+");
+ int sigrt = sig-SIGRTMIN;
+
+ if (sigrt < 10)
+ {
+ str[6] = '0'+sigrt;
+ str[7] = '\0';
+ }
+ else
+ {
+ str[6] = '0'+sigrt/10;
+ str[7] = '0'+sigrt%10;
+ str[8] = '\0';
+ }
+
+ return 0;
+ }
+
+ return -1;
+}
--
2.44.2
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.