In which header file are EINVAL, ENOMEM, etc. defined in Linux?

27.5k views Asked by At

It’s said that the error numbers like EINVAL, ENOMEM, etc. are defined in errno.h, but I can’t find them in errno.h, I also searched some directories under /usr/include, still can’t find them. I can use these macros without any issue in my C code. Anyone can tell me where are them?

3

There are 3 answers

0
rohit89 On

You can run locate errno.h | xargs grep EINVAL to find the location

On my Ubuntu 12.04 machine, its in /usr/lib/syslinux/com32/include/errno.h

0
unwind On

It's up to the implementation of the standard C library.

All that is certain is that <errno.h> is the top-level header that application code should use.

One way of figuring out is to trace an invocation of the compiler.

1
Klas Lindbäck On

It is defined either directly in errno.h or in a file included (directly or indirectly) by errno.h.

I searched for it using the following command:

find /usr/include | xargs grep ENOMEM | grep '#define'

and I found a match in /usr/include/asm-generic/errno-base.h in my linux (RHEL 6).