Question

I have a code which checks the presence of certain system calls via something like

#if defined(__NR_process_vm_readv)

blah blah

#else 

blah2 blah2

#endif

After running the source file through the pre-processor I see that the code in #else is being compiled. The reason is that the the unistd.h which is included resides under /usr/include whereas the unistd.h file which has those particular defines is under /usr/include/asm-generic/unistd.h. So how am I supposed to include it? The code I'm working has been written by a 3rd party so I don't know if the strategy that they opted to follow is even correct (relying on those defines).

Était-ce utile?

La solution

The right way to do this on linux is shown in the syscall(2) manual page (see for example http://man7.org/linux/man-pages/man2/syscall.2.html):

#include <unistd.h>
#include <sys/syscall.h>

possibly with a preceding "#define _GNU_SOURCE" or other system specifier, though that doesn't seem to be necessary on my system. The <sys/syscall.h> file actually includes <asm/unistd.h>. This provides the SYS_syscall definition as well as __NR_syscall

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top