aboutsummaryrefslogtreecommitdiffstats
path: root/consts.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2020-05-31 00:23:22 +0200
committerMattias Andrée <maandree@kth.se>2020-05-31 00:23:22 +0200
commit4383640bfe4c40c055824d9c42ed8809bb3163b4 (patch)
treedf194cbc3764320a88e25e1f77855aaaed4631ea /consts.c
parentWork around valgrind issue (diff)
downloadsctrace-4383640bfe4c40c055824d9c42ed8809bb3163b4.tar.gz
sctrace-4383640bfe4c40c055824d9c42ed8809bb3163b4.tar.bz2
sctrace-4383640bfe4c40c055824d9c42ed8809bb3163b4.tar.xz
Print signal names
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'consts.c')
-rw-r--r--consts.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/consts.c b/consts.c
index 567a6e7..4e68230 100644
--- a/consts.c
+++ b/consts.c
@@ -26,3 +26,32 @@ get_errno_name(int err)
sprintf(buf, "%i", err);
return buf;
}
+
+
+const char *
+get_signum_name(int sig)
+{
+ static char buf[3 * sizeof(sig) + 2];
+ int above_low, below_high;
+
+#define X(N) if (sig == N) return #N;
+ LIST_SIGNUMS(X)
+#undef X
+
+ if (__SIGRTMIN <= sig && sig <= __SIGRTMAX) {
+ above_low = sig - __SIGRTMIN;
+ below_high = __SIGRTMAX - sig;
+ if (!above_low)
+ return "__SIGRTMIN";
+ if (!below_high)
+ return "__SIGRTMAX";
+ if (above_low <= below_high)
+ sprintf(buf, "__SIGRTMIN+%i", above_low);
+ else
+ sprintf(buf, "__SIGRTMAX-%i", below_high);
+ return buf;
+ }
+
+ sprintf(buf, "%i", sig);
+ return buf;
+}