I’m trying to understand the Linux kernel, so I’m reading Linux kernel source. So how can I determine where a header file located, because there are many header files have the same name but locate in different directories?
Example: they include fcntl.h in fs/open.c
I can find fcntl.h in 17 different directories
arch/alpha/include/asm/fcntl.h
arch/arm/include/asm/fcntl.h
....
Generally, it’s going to depend on the way the file was included. If included with quotes like this:
It should be in the same directory. (It can also be in the “include” directories.)
If included with angle brackets like this:
It’s located in an “include” directory. These are directories that the compiler is told at compile-time to search in for header files. These can be passed as parameters, or set in an environment variable.
For the examples provided, the directories make it clear why there are duplicates: generally, different architecture-specific files are separated by folders named for different architectures.
In the example provided, you’re looking at different fcntl.h files for the Alpha and ARM architectures. The file your compiler will use depends on the CPU being compiled for, and the compiler will be told which to use during compile time.
In my personal opinion, if you don’t already know this, you may be starting in the wrong place to understand the linux kernel. Try first researching C