file descriptor vs file handle
Doug Gwyn
gwyn at smoke.brl.mil
Wed Feb 27 06:56:48 AEST 1991
In article <27C9CB35.5F7 at wilbur.coyote.trw.com> cwong at charlie.coyote.trw.com (Chun Wong) writes:
>I know that creat returns a file handle whereas fopen
>returns a file descriptor. What's the difference? Are they interchangeable?
How can you "know" something that is false?
On UNIX, which is the prototypical C environment, there is a set of
system calls open(), creat(), read(), write(), close(), ioctl(), dup(),
etc. that operate using I/O access information maintained within the
operating system kernel, in tables that are indexed by small integers
called "file descriptors". Such system calls do not necessarily exist
for other operating system environments, so various "portable I/O
library" interfaces were devised, leading to the "standard I/O library"
described in K&R which served as the basis for the C standard's hosted-
implementation required I/O support. The standard I/O package may or
may not make use of file descriptors internally, but it provides for
use by application programs pointers to FILE structures, sometimes
called "stream pointers". A FILE structure contains implementation-
specific information needed for the standard I/O functions to do their
job properly. By the way, standard I/O also supports buffering of I/O
data into fairly large blocks, which are read/written a blockful at a
time. This allows use of functions such as getc() and putc() without
the horribly expensive overhead that would arise if operating system
I/O requests were performed for each byte individually.
More information about the Comp.lang.c
mailing list