lovecreatesbeauty said:
In the C programming language, I/O operation functions are declared in
stdio.h, for example, fopen(), fclose(), fwrite(), fread(), fseek() ...
But another set of I/O functions are also defined in Unix, for example,
open(), close(), read(), write(), lseek() ...
Which set of functions is more suitable for I/O task, C library version
or Unix version?
To the question in your subject line: C's I/O and Unix'
I/O are different because C can operate on systems that are
not Unix.
To the question in your message: Neither set of functions
is always "more suitable." Which is more suitable: a hammer
or a saw? A hand-operated drill, a battery-powered drill, a
portable drill powered by house current, or a fixed-position
drill press? It all depends on the task at hand and on where
you want to be able to do it.
Various responders have offered information that's either
incorrect, incomplete, or misleading. Rather than post a
whole flurry of rebuttals, I'll package them all here:
richselby says fopen() and friends are library functions
while open() and the like are system calls. That's a detail
of the implementation, true on many systems but certainly
not on all. On some systems, both fopen() and open() are
library functions.
loufoque opines that only POSIX-compliant systems are any
good. It's pointless to dispute his (?) opinion, but the
implication that open() and friends on POSIX systems share
all the characteristics found in Unix implementations.
Lucien Kennedy-Lamb explains that fopen() and friends are
higher-level functions that rest upon lower-level system calls
like open(). This is really just richselby's mistake all over
again: It's often true, but not universally true.
Summary: fopen() and friends are part of the C Standard
library, found in all hosted C implementations, even those
that do not run under Unix or under POSIX. open() and the
like are specified by POSIX, but only in terms of what they
do, not how they do it. They may or may not be "system calls,"
and they may or may not be "lower level" calls.