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?
You should include all these header files. The headers mentioned in the synopsis are all supposed to be included.
AFAIK, you should include all those header files. Why do you need to know which header file contains macros, functions or typedefs, if you eventually include all of them?