From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id 42364277C6 for ; Fri, 9 Aug 2024 17:34:53 +0200 (CEST) Received: (qmail 5663 invoked by uid 550); 9 Aug 2024 15:34:35 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 5567 invoked from network); 9 Aug 2024 15:34:35 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=hacktivis.me; h=from:to :cc:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=20240308_115322; bh=aYHa5Wsoy8bpUS jDrOwUTgcv5BUssTfp7vITEQ0QC+k=; b=Lj+SqBb6/HgxwG8b+ajeAqaY8uKb4H 7UVcX0FWml5ZNcI3jx8YQkFGmFdrQTs1ivZyqx28xNUfCbk/bdbDULW2PscUYb+6 12fHhLONIb9v232Emfn1FI5zcX1bqe0bUhF9hjJlcR2+lCWLiaIBp68ioOpCDCSv kgVP4jIGLqd4C2yDLlnHexlG1bjheaaiWOeFtF4opcmteAjVbSMX2mhdXg11E2yd R03t7MxK2NQxSnwVOjDc7HTVDRLoU2HbseS6JgNoCi3ZjcuqUnHBtxwgCdN+rOGU HPUiCSzLshd6VV5qp/U5kZnQjGyLRXXLGcNWZqHHmChPR9ZdT6tkdViF0lY7Ydym fkFFCKfbSgQ2urHT3QOFMet+xmdDyvREUPTsk+zb1Flfiys6K5lng2pzgxgQxDs2 Alh5TunJGegjCbuzD9b6bsiUu3XnYv9EzSLc8+dB+ynEjr2g6bVGsYkT/xc4/LCc lGRjaQhrqJsoAfXYad+9tUwVSdfWrKty9LDhbd9335ee68s7gUHuyv71gJRQhElV Fw4kd6QP1igfgUzO5oHiQE4qt/P4L4A0Z8u6nSMil4AjR5ukMRZiE1WVOX0N2Ha3 IJ9lBHeMQ2WUy6GiRK3K5R/pcL8/HkdGmkFz1m8g3bWWqqx8uvWjmR72x4cwy/xd IQv775AkV42FA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=hacktivis.me; h=from:to:cc :date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; q=dns; s=20240308_115322; b=YCQkHXd6 lFOF+fbEzyojIh20I8qqMcXt1O+E7qVD5ni23CsHGHmmog48yOk0MFUBBaVvB+nz x21rnd7FcV9D1zNzOohF7VHj4hT63ERrkdwmxZ93+O9hhDE07VYjxCPm5qotHIr+ gBxdSJyrZxhcaHnusA0y3Uz9oRycOJT5WmWOgsokgBE9x/kPlSmJRpRdikkBK/FU 0yPNvA3J+Mjf10gaLoU+FjiXEvsL9AHEVDk3weB8xgieA9dL3fFYGwsoFA1EFAai XAzOO9JjHksI/LThw3J4k3vTs+TPClP6euARxbGaUdFEQ9mFGbApqHeb1fhPKTOn C0hAnyM82V8HfrpObYyLqK9OXeW3ueSWn+w3IvcfR87uhNgAAD3NBI3HWmwjjKER L4ljXeVNX+MIeeR7Q05LnPPUFRxi04/aXCHLjyuxQydw4Ln/kmsEdjC/s+ZN5Gtm jWafSdSES709+nJqsFOYQw7upH1/2FpNC0rvaTBWDEAUgSFV2g1tWA96YyFjSYc2 RLqWBFndN1OxFmwQAE9ISeC8CqHaD2v3uWissXninjm91T6hLazVg3LVH0m5cNR+ Cj5OGCXaevAV0jtOgH4VItBgQT3w3tSbaSomO5eNN+0tbcR89aIPC6H/0+iATDe5 be59xQWwYoTWjV+DsemOFG8h3oxnQl1dDCM= From: contact@hacktivis.me To: musl@lists.openwall.com Cc: "Haelwenn (lanodan) Monnier" Date: Fri, 9 Aug 2024 17:34:22 +0200 Message-ID: <20240809153423.30829-2-contact@hacktivis.me> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240809153423.30829-1-contact@hacktivis.me> References: <20240809153423.30829-1-contact@hacktivis.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [musl] [PATCH v3 2/3] signal: add sig2str(3) from POSIX.1-2024 From: "Haelwenn (lanodan) Monnier" --- include/signal.h | 5 +++++ src/signal/sig2str.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/signal/sig2str.c diff --git a/include/signal.h b/include/signal.h index c347f861..94ac29b1 100644 --- a/include/signal.h +++ b/include/signal.h @@ -233,6 +233,11 @@ int pthread_kill(pthread_t, int); void psiginfo(const siginfo_t *, const char *); void psignal(int, const char *); +// SIG2STR_MAX needs to at least fit "RTMIN+nn" (9 bytes) +// Bumped to 13 to be safe if a case like "SIGRTMIN+nnn" happens +#define SIG2STR_MAX 13 +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..989d3645 --- /dev/null +++ b/src/signal/sig2str.c @@ -0,0 +1,34 @@ +#include +#include + +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 (sig > SIGRTMIN && sig <= SIGRTMAX) + { + strcpy(str, "RTMIN+"); + int sigrt = sig-SIGRTMIN; + + char *s = str+6; + if (sigrt>=10) + { + *s++ = '0' + sigrt/10; + sigrt %= 10; + } + *s++ = '0' + sigrt; + *s = '\0'; + + return 0; + } + + return -1; +} -- 2.44.2