>From 5ddebacde40d9f0150cd22ce8066a1ae7d6f90fd Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 21 Sep 2026 18:27:14 -0400 Subject: [PATCH 13/23] convert strsignal to use new locale string table lookups we already had a remapping to a common numbering used with the old multistring linear search implementation of strsignal; that mapping is kept, with a small change to map the mips-specific SIGEMT that replaces SIGSTKFLT to its own number (-1), so that the same key is not used for two different meanings. --- src/string/strsignal.c | 93 ++++++++------------------- src/string/strsignal.h | 140 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 167 insertions(+), 66 deletions(-) create mode 100644 src/string/strsignal.h diff --git a/src/string/strsignal.c b/src/string/strsignal.c index f5da0f54..4024d43f 100644 --- a/src/string/strsignal.c +++ b/src/string/strsignal.c @@ -2,6 +2,24 @@ #include #include "locale_impl.h" +enum { NEG1 = -1 }; +#define M_TABLE "../string/strsignal.h", strsignal_data, -1 +#define ERRDOMAIN_SIGNAL 5 + +static const struct { + unsigned char header[8]; + unsigned char offsets[8]; + struct { + #include "mdecl.h" + } errors; +} strsignals = { + .header = { 0,0,0,0,0,0,0,8-1, }, + .offsets = { [ERRDOMAIN_SIGNAL] = 1 }, + .errors = { + #include "mdata.h" + }, +}; + #if (SIGHUP == 1) && (SIGINT == 2) && (SIGQUIT == 3) && (SIGILL == 4) \ && (SIGTRAP == 5) && (SIGABRT == 6) && (SIGBUS == 7) && (SIGFPE == 8) \ && (SIGKILL == 9) && (SIGUSR1 == 10) && (SIGSEGV == 11) && (SIGUSR2 == 12) \ @@ -15,7 +33,7 @@ #else -static const char map[] = { +static const signed char map[] = { [SIGHUP] = 1, [SIGINT] = 2, [SIGQUIT] = 3, @@ -33,8 +51,9 @@ static const char map[] = { [SIGTERM] = 15, #if defined(SIGSTKFLT) [SIGSTKFLT] = 16, -#elif defined(SIGEMT) - [SIGEMT] = 16, +#endif +#if defined(SIGEMT) + [SIGEMT] = -1, #endif [SIGCHLD] = 17, [SIGCONT] = 18, @@ -57,70 +76,12 @@ static const char map[] = { #endif -static const char strings[] = - "Unknown signal\0" - "Hangup\0" - "Interrupt\0" - "Quit\0" - "Illegal instruction\0" - "Trace/breakpoint trap\0" - "Aborted\0" - "Bus error\0" - "Arithmetic exception\0" - "Killed\0" - "User defined signal 1\0" - "Segmentation fault\0" - "User defined signal 2\0" - "Broken pipe\0" - "Alarm clock\0" - "Terminated\0" -#if defined(SIGSTKFLT) - "Stack fault\0" -#elif defined(SIGEMT) - "Emulator trap\0" -#else - "Unknown signal\0" -#endif - "Child process status\0" - "Continued\0" - "Stopped (signal)\0" - "Stopped\0" - "Stopped (tty input)\0" - "Stopped (tty output)\0" - "Urgent I/O condition\0" - "CPU time limit exceeded\0" - "File size limit exceeded\0" - "Virtual timer expired\0" - "Profiling timer expired\0" - "Window changed\0" - "I/O possible\0" - "Power failure\0" - "Bad system call\0" - "RT32" - "\0RT33\0RT34\0RT35\0RT36\0RT37\0RT38\0RT39\0RT40" - "\0RT41\0RT42\0RT43\0RT44\0RT45\0RT46\0RT47\0RT48" - "\0RT49\0RT50\0RT51\0RT52\0RT53\0RT54\0RT55\0RT56" - "\0RT57\0RT58\0RT59\0RT60\0RT61\0RT62\0RT63\0RT64" -#if _NSIG > 65 - "\0RT65\0RT66\0RT67\0RT68\0RT69\0RT70\0RT71\0RT72" - "\0RT73\0RT74\0RT75\0RT76\0RT77\0RT78\0RT79\0RT80" - "\0RT81\0RT82\0RT83\0RT84\0RT85\0RT86\0RT87\0RT88" - "\0RT89\0RT90\0RT91\0RT92\0RT93\0RT94\0RT95\0RT96" - "\0RT97\0RT98\0RT99\0RT100\0RT101\0RT102\0RT103\0RT104" - "\0RT105\0RT106\0RT107\0RT108\0RT109\0RT110\0RT111\0RT112" - "\0RT113\0RT114\0RT115\0RT116\0RT117\0RT118\0RT119\0RT120" - "\0RT121\0RT122\0RT123\0RT124\0RT125\0RT126\0RT127\0RT128" -#endif - ""; - char *strsignal(int signum) { - const char *s = strings; - - signum = sigmap(signum); - if (signum - 1U >= _NSIG-1) signum = 0; - - for (; signum--; s++) for (; *s; s++); + static const int unknown[] = LPATH(ERRDOMAIN_SIGNAL, 0); + const int path[] = LPATH(ERRDOMAIN_SIGNAL, signum); - return (char *)s; + return (char *)__loc_lookup((const void *)&strsignals, + LMEMB(CURRENT_LOCALE,LC_MESSAGES,errors), + path, unknown); } diff --git a/src/string/strsignal.h b/src/string/strsignal.h new file mode 100644 index 00000000..731b8c24 --- /dev/null +++ b/src/string/strsignal.h @@ -0,0 +1,140 @@ +M(0, "Unknown signal") +M(1, "Hangup") +M(2, "Interrupt") +M(3, "Quit") +M(4, "Illegal instruction") +M(5, "Trace/breakpoint trap") +M(6, "Aborted") +M(7, "Bus error") +M(8, "Arithmetic exception") +M(9, "Killed") +M(10, "User defined signal 1") +M(11, "Segmentation fault") +M(12, "User defined signal 2") +M(13, "Broken pipe") +M(14, "Alarm clock") +M(15, "Terminated") + +#ifdef SIGSTKFLT +M(16, "Stack fault") +#endif + +M(17, "Child process status") +M(18, "Continued") +M(19, "Stopped (signal)") +M(20, "Stopped") +M(21, "Stopped (tty input)") +M(22, "Stopped (tty output)") +M(23, "Urgent I/O condition") +M(24, "CPU time limit exceeded") +M(25, "File size limit exceeded") +M(26, "Virtual timer expired") +M(27, "Profiling timer expired") +M(28, "Window changed") +M(29, "I/O possible") +M(30, "Power failure") +M(31, "Bad system call") +M(32, "RT32") + +M(33, "RT33") +M(34, "RT34") +M(35, "RT35") +M(36, "RT36") +M(37, "RT37") +M(38, "RT38") +M(39, "RT39") +M(40, "RT40") +M(41, "RT41") +M(42, "RT42") +M(43, "RT43") +M(44, "RT44") +M(45, "RT45") +M(46, "RT46") +M(47, "RT47") +M(48, "RT48") +M(49, "RT49") +M(50, "RT50") +M(51, "RT51") +M(52, "RT52") +M(53, "RT53") +M(54, "RT54") +M(55, "RT55") +M(56, "RT56") +M(57, "RT57") +M(58, "RT58") +M(59, "RT59") +M(60, "RT60") +M(61, "RT61") +M(62, "RT62") +M(63, "RT63") +M(64, "RT64") + +#if _NSIG > 65 +M(65, "RT65") +M(66, "RT66") +M(67, "RT67") +M(68, "RT68") +M(69, "RT69") +M(70, "RT70") +M(71, "RT71") +M(72, "RT72") +M(73, "RT73") +M(74, "RT74") +M(75, "RT75") +M(76, "RT76") +M(77, "RT77") +M(78, "RT78") +M(79, "RT79") +M(80, "RT80") +M(81, "RT81") +M(82, "RT82") +M(83, "RT83") +M(84, "RT84") +M(85, "RT85") +M(86, "RT86") +M(87, "RT87") +M(88, "RT88") +M(89, "RT89") +M(90, "RT90") +M(91, "RT91") +M(92, "RT92") +M(93, "RT93") +M(94, "RT94") +M(95, "RT95") +M(96, "RT96") +M(97, "RT97") +M(98, "RT98") +M(99, "RT99") +M(100, "RT100") +M(101, "RT101") +M(102, "RT102") +M(103, "RT103") +M(104, "RT104") +M(105, "RT105") +M(106, "RT106") +M(107, "RT107") +M(108, "RT108") +M(109, "RT109") +M(110, "RT110") +M(111, "RT111") +M(112, "RT112") +M(113, "RT113") +M(114, "RT114") +M(115, "RT115") +M(116, "RT116") +M(117, "RT117") +M(118, "RT118") +M(119, "RT119") +M(120, "RT120") +M(121, "RT121") +M(122, "RT122") +M(123, "RT123") +M(124, "RT124") +M(125, "RT125") +M(126, "RT126") +M(127, "RT127") +#endif + +#ifdef SIGEMT +M(NEG1, "Emulator trap") +#endif -- 2.21.0