Francis said:
Hello,
I'd like to understand this topic.
For example I need to use open, read functions that operate on a
file. I would think to need to include only one header file for these
functions but instead I need to include unistd.h and fcntl.h.
Could anybody explain me why ?
If you are writing standard C, you don't need to include unistd.h or
fcntl.h. In fact, they don't exist in C at all. If you have them, they
are a feature of your implementation. The standard header for functions
that operate on files is <stdio.h>.
You might ask, then, why don't open() and read() work with the inclusion
of <stdio.h>? They don't work because they are not part of the standard
C library. If you have them, they are system-specific functions
provided in some non-standard library. The standard C function for
opening a file is fopen() and the standard C functions for reading a
file include -- among a number of others -- fread().
If you really feel you need open(), read(), unistd.h, and fcntl.h, your
question belongs in an implementation or OS-specific newsgroup, as the
name unistd.h might suggest to you. If you want to use the standard C
library, then your questions are just fine here. But you need to decide
for yourself which path you will take. The standard functions, in
addition to being topical here, provide you with the ability to move to
any other implementation supporting the standard C library. That is not
true of your unix-specific headers and functions any more than it would
be true of windows-specific headers and functions.