diff options
author | Mattias Andrée <maandree@kth.se> | 2020-05-31 00:23:22 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2020-05-31 00:23:22 +0200 |
commit | 4383640bfe4c40c055824d9c42ed8809bb3163b4 (patch) | |
tree | df194cbc3764320a88e25e1f77855aaaed4631ea /consts.c | |
parent | Work around valgrind issue (diff) | |
download | sctrace-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.c | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -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; +} |