]> granicus.if.org Git - strace/commitdiff
tests: add signal2name function to libtests
authorFei Jie <feij.fnst@cn.fujitsu.com>
Thu, 16 Jun 2016 02:42:13 +0000 (10:42 +0800)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 16 Jun 2016 12:39:56 +0000 (12:39 +0000)
* tests/tests.h (signal2name): New prototype.
* tests/signal2name.c: New file.
* tests/Makefile.am (libtests_a_SOURCES): Add it.

tests/Makefile.am
tests/signal2name.c [new file with mode: 0644]
tests/tests.h

index 7a029b63112a77d9def3f4ffc2209a4ad469c9a5..a136e2aec4fdc53dac701ad1926619ddb92e0e47 100644 (file)
@@ -51,6 +51,7 @@ libtests_a_SOURCES = \
        print_quoted_string.c \
        printflags.c \
        printxval.c \
+       signal2name.c \
        tail_alloc.c \
        tests.h \
        tprintf.c \
diff --git a/tests/signal2name.c b/tests/signal2name.c
new file mode 100644 (file)
index 0000000..e301f4e
--- /dev/null
@@ -0,0 +1,55 @@
+#include "tests.h"
+#include <signal.h>
+
+#define CASE(x) case x: return #x
+
+const char *
+signal2name(int sig)
+{
+       switch (sig) {
+       CASE(SIGALRM);
+       CASE(SIGBUS);
+       CASE(SIGCHLD);
+       CASE(SIGCONT);
+       CASE(SIGFPE);
+       CASE(SIGHUP);
+       CASE(SIGILL);
+       CASE(SIGINT);
+       CASE(SIGIO);
+       CASE(SIGPIPE);
+       CASE(SIGPROF);
+       CASE(SIGQUIT);
+       CASE(SIGSEGV);
+       CASE(SIGSYS);
+       CASE(SIGTERM);
+       CASE(SIGTRAP);
+       CASE(SIGTSTP);
+       CASE(SIGTTIN);
+       CASE(SIGTTOU);
+       CASE(SIGURG);
+       CASE(SIGUSR1);
+       CASE(SIGUSR2);
+       CASE(SIGVTALRM);
+       CASE(SIGWINCH);
+       CASE(SIGXCPU);
+       CASE(SIGXFSZ);
+#if defined ALPHA
+       CASE(SIGABRT);
+       CASE(SIGEMT);
+       CASE(SIGINFO);
+#elif defined SPARC || defined SPARC64
+       CASE(SIGABRT);
+       CASE(SIGEMT);
+       CASE(SIGLOST);
+#elif defined MIPS
+       CASE(SIGEMT);
+       CASE(SIGIOT);
+       CASE(SIGPWR);
+#else
+       CASE(SIGABRT);
+       CASE(SIGPWR);
+       CASE(SIGSTKFLT);
+#endif
+       default: perror_msg_and_fail("unknown signal number %d", sig);
+       }
+}
index 9f556ae4fa97254f7702cff33c9a7055ffbf7dc3..02d588edf5d1ebdbe6f83080071dd8f827a021a3 100644 (file)
@@ -93,6 +93,9 @@ void check_overflowgid(const int);
 /* Translate errno to its name. */
 const char *errno2name(void);
 
+/* Translate signal number to its name. */
+const char *signal2name(int);
+
 struct xlat;
 
 /* Print flags in symbolic form according to xlat table. */