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 BC35028674 for ; Mon, 5 Aug 2024 08:56:36 +0200 (CEST) Received: (qmail 32739 invoked by uid 550); 5 Aug 2024 06:56:21 -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 32647 invoked from network); 5 Aug 2024 06:56:20 -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=IQNIbL9ehyJZ4t YBtM09NFeuRNtchRu14pqoUqI1ocw=; b=nttzmF31ACOjbAitkbSEh8BplG06sw 9KaXrQRhmZXW1TBnO3SiajTEzmFcmxT073419on6FIdevaU6uj85mYLI+QzyAffV vbJdtT3iIwSWXml5NEPzn/3cnjltgkfAaIkHjVMuytkaErjzyoREB59BhjiD0y3n OyN6cNPNw7s28y03QtequJkAkTnXQtok7jUaQqobisxxAM5H1JJ9ld7QWGsIVVXp 7x0TzNgoL17w6pP+4wkoR7DUCmL0mjdK+HF1hZAU8l91r3j28k2ny8ZE9Egf8z7N Lo0mWmq335x0vbCfIOVBRUGnr02CsARQvNHpz8X8plR9oUlCsKGzwzfK/YP5to9E s3tUYfzd4gtcUSFBOu97FdKY3CERlxNrjWMOEo6KiDHDB48t7WuneqUjpJEZxsW/ 73eGbRngmFnDPHH0Q9l9Ht4HocfzfoQjSDQcgfVMB1sWbzqLTiGSoFmcD3ajBtwI NAUDkzwj6YmRShrJEZ4WpPFzc65GyTnXJcB7axC2DIdNsJVw+LldvKJhhW/SvRC7 bcZAp1+x6AVG7IOA5zaaMc9OReV/CgjRgXra0OaZMfo1kWvKVf1vbgA2QCtEaVuk 7AfdaNWybS3sGMBqQnPCoqYnnOTVXiMlM59eM5fMSqs/uxVLfBZpalF4QS+6MA9z ZO98rsA1++7Us= 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=ps3KEkRA quntgJQHzrb1ztlII+B6tFNUBzeJItzRBpmafzuQw5c3nHa60ZhNq39sScCpcw7d tZDAnXoUmU84zc+tLhii5PTdhHZPyRVgndJVl8iZYgo7l3RT/1ekZIEvt9DKNSft 618S124quYO98HgaDDMNvsx1ec2KMrM/NeuTwUUoh3frhD1ILFXz0iXWaAiVS0nW phkz4PYcUkWlS7KLVtkDoFI69hbgCnNYLQbUyu/uWcCewb+FAgUN/3ya68v5fiK9 5mUtaHVUw7KCJ3P5owpbfItrAKnuyQDj86H5+XTL3PnBcVaUfgqxpcnUgp+wDY3D bojU4ETN1UpNyNxzbbEbm+V/TVOSLK67sjLWystUtFuWEHZ4n7lSEs+/QmIXqPO4 16yw/HoLcRNzh05XnFHsyRP3wOifHkQVOq3yyPctg7SLxJCBgcGV/S6FgCsoAX83 oNmcc5YuI3UcVgJwKehXAJE0N4SN7nrorvVmzMN1o6o5zi+EmWIBgM22ZBcqsG8h Ivj/Ero1YCc15cZ1u2Vsj0474+u00+OdmIvGPrsPdx9dK8E7+/U21bk7pO7wG9Ez kL12NOfzyVRlgoe15ACOP7lCQR7nx/kPpc5hFJead87OpgDEK4i+6iKGCfYdwQRw KnbiFIVRFTg5Hr0RDT0Be/daVuU2bUESVnU= From: contact@hacktivis.me To: musl@lists.openwall.com Cc: "Haelwenn (lanodan) Monnier" Date: Mon, 5 Aug 2024 08:56:06 +0200 Message-ID: <20240805065607.22897-2-contact@hacktivis.me> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240805065607.22897-1-contact@hacktivis.me> References: <20240805065607.22897-1-contact@hacktivis.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [musl] [PATCH v2 2/3] signal: add sig2str(3) from POSIX.1-2024 From: "Haelwenn (lanodan) Monnier" --- 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 +#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 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