Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why are there multiple fcntl.h in linux?

I write a c program which includes fcntl.h file. I search the file and get results as follow:

[xunyl@localhost csapp]$ find /usr/include/ -name "fcntl.h"
/usr/include/asm/fcntl.h
/usr/include/asm-generic/fcntl.h
/usr/include/linux/fcntl.h
/usr/include/sys/fcntl.h
/usr/include/bits/fcntl.h
/usr/include/fcntl.h

[xunyl@localhost csapp]$ grep -rn "O_RDONLY" /usr/include/
/usr/include/asm-generic/fcntl.h:19:#define O_RDONLY    00000000
/usr/include/linux/cdrom.h:32: *       -    drive = open("/dev/cdrom", O_RDONLY);
/usr/include/linux/cdrom.h:33: *       +    drive = open("/dev/cdrom", O_RDONLY | O_NONBLOCK);
...

I find gcc calls /usr/include/asm-generic/fcntl.h actually when I put #include <fcntl.h> in program. I just wonder how gcc determines which "fcntl.h" should be called. Is there any call order or precedence ?

like image 820
xunyulin Avatar asked Apr 05 '16 06:04

xunyulin


People also ask

What is Fcntl h in Linux?

Description. The /usr/include/fcntl. h file defines the values that can be specified for the Command and Argument parameters of the fcntl subroutine and for the Oflag parameter of the open subroutine. The file-status flags of an open file are described in the following information. Flag Values for open Subroutine.

Why do we use Fcntl H?

h is the header in the C POSIX library for the C programming language that contains constructs that refer to file control, e.g. opening a file, retrieving and changing the permissions of file, locking a file for edit, etc.

What does Fcntl return?

If a shared or exclusive lock cannot be set, fcntl() will return immediately with a return value of -1. This command is the same as F_SETLK except that if a shared or exclusive lock is blocked by other locks, the thread will wait until the request can be satisfied.


1 Answers

One includes another which includes the next until the one with the definition is included.

like image 99
Ignacio Vazquez-Abrams Avatar answered Oct 12 '22 15:10

Ignacio Vazquez-Abrams