I want to build an unique error number, which consists of a random number and the errno
of a system call. Example:
#define ERRID(ERRNO) ((uint32_t)rand() << 16 | (uint32_t)(ERRNO) & 0xFFFF)
I need to know how many bits are required to store an errno
value.
I know it is defined as int
. But the total number of errors is much lower than 9,223,372,036,854,775,807 on a 64 bit system. On my Debian the maximum number seems to be 529.
dpkg -L linux-headers-3.16.0-4-common|
grep errno.h|
xargs cat|
awk '/^#define/{print $3}'|
sort -rn|
head -1
529
So uint16_t
seems to be enough to store the errno
.
But how to be sure? How can I find out how many errnos the operating system actually uses? Is it documented anywhere?