why not give people different headers
They already got them; the headers are divided by topic into files, so it takes another dimension to filter.
I was looking for a signal number-to-name conversion. I found strsignal()
, in <string.h>
. The man page says:
sigabbrev_np(), sigdescr_np():
_GNU_SOURCE <<< not default
strsignal():
From glibc 2.10 to 2.31:
_POSIX_C_SOURCE >= 200809L <<< default, cf. XOPEN2K8 below
Before glibc 2.10:
_GNU_SOURCE
I had never really cared for this part at all. sigabbrev_np()
is not included in the default "features". string.h
shows how:
#ifdef __USE_XOPEN2K8
/* Return a string describing the meaning of the signal number in SIG. */
extern char *strsignal (int __sig) __THROW;
# ifdef __USE_GNU
/* Return an abbreviation string for the signal number SIG. */
extern const char *sigabbrev_np (int __sig) __THROW;
/* Return a string describing the meaning of the signal number in SIG,
the result is not translated. */
extern const char *sigdescr_np (int __sig) __THROW;
# endif
__USE_GNU
can/should be set via _GNU_SOURCE
, at compilation or top of the file. But that "activates" all other such ifdeffed declarations in all headers, too. (Unless you define-undefine per header)
So to explicitly import just one (or the other) special function, I go like this for now (copy-paste. I left the "THROW" and changed "__sig"):
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
extern const char *sigabbrev_np(int sig) __THROW; /* __USE_GNU / _GNU_SOURCE */
#include <errno.h>
#include <elf.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
...
Now sigabbrev_np(wstate >> 8)
gives me TRAP
etc. without #defines.
I had a hard time realizing that 0x57f
means OK because 5
is TRAP
, but 0xb7f
and 0x77f
are SEGV
and BUS
--- which I got depending on where I set the breakpoint, sometimes after thousands of instructions. Because I did not step back the intruction pointer...