Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is open declared in fcntl.h, while close is declared in unistd.h?

Tags:

unix

posix

In POSIX, why is the open system call declared in fcntl.h, while the close system call is declared in unistd.h? I presume this is a historical artifact, but this pair strikes me as especially odd since you often need to close after open.

like image 567
Doug Richardson Avatar asked Mar 12 '14 17:03

Doug Richardson


People also ask

Why Fcntl H is used?

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.

Is Unistd h in the standard library?

No, unistd. h and fcntl. h , etc are not part of standard C.


1 Answers

As previously pointed out, sockets and pipes also get passed to close. But probably the original reason is that open needs flags like O_RDONLY that are defined in fcntl.h, so you might as well put the prototype in that file.

like image 162
user3188445 Avatar answered Nov 13 '22 15:11

user3188445