Which Header Files to Use?

The UNIX header files are an excellent source of information to understand user-level programming and also kernel-level data structures. Most of the header files that are needed for user level programming can be found under/usr/include and /usr/include/sys.

The header files that are needed are shown in the manual page of the library function or system call to be used. For example, using the stat() system call requires the following two header files:

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

int stat(const char path, struct stat buf);

The stat.h header file defines the stat structure. The types.h header file defines the types of each of the fields in the stat structure.

Header files that reside in /usr/include are used purely by applications. Those header files that reside in /usr/include/sys are also used by the kernel. Using stat() as an example, a reference to the stat structure is passed from the user process to the kernel, the kernel fills in the fields of the structure and then returns. Thus, in many circumstances, both user processes and the kernel need to understand the same structures and data types.

Get UNIX Filesystems: Evolution, Design, and Implementation now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.