Search code examples
clinuxposixbsdmanpage

Should I include any or all of the headers listed in the synopsis of a man page?


For example, take open(2), which has the following synopsis:

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int open(const char *pathname, int flags);
int open(const char *pathname, int flags, mode_t mode);
int creat(const char *pathname, mode_t mode);

Should I include all those header files or is any one of those fine? In the former case, how do I know which header files contain which functions, macros and typedefs?


Solution

  • You should include all of them. The POSIX specification will tell you what's in each (for instance, this is the POSIX specification for fcntl.h), or at least what's guaranteed to be in each.