file descriptor vs file handle

Zack C. Sessions session at uncw.UUCP
Wed Feb 27 05:33:09 AEST 1991


cwong at charlie.coyote.trw.com (Chun Wong) writes:

>Can someone distinguish the differences between a file descriptor and
>a file handle?  I know that creat returns a file handle whereas fopen
>returns a file descriptor.  What's the difference?  Are they interchangeable?

>-C. Wong

A file handle as you call it is also referred to as a path. It is
typically an int variable and is used by creat and open and read
and write and close. (plus others). A File Descriptor is a special
structure which is specific for your system and defined in your
stdio.h defs file. It usually contains a file handle (path) as part
of it's data structure. Files which you access with File Descriptors
use the fopen, printf and scanf constructs, fread, fwrite, and
fclose (plus others). The distinct difference between the two is
that files accessed through a File Descriptor are accessed in
a method call "buffered IO". This can sometimes greatly increase
the performance of your program at runtime. Also, the "raw IO"
calls are not always implemented the same on all machines or
compilers and sometimes not implemented at all. Use of only
buffered IO can usually guarantee portability if that's an
issue.

Zack Sessions
...!ecsvax!uncw!session



More information about the Comp.lang.c mailing list