file descriptor vs file handle

Tim Campbell campbell at dev8n.mdcbbs.com
Tue Feb 26 21:10:38 AEST 1991


In article <27C9CB35.5F7 at wilbur.coyote.trw.com>, 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
-- 
I'm reciting this from memory - I haven't had to use it in a while so if I
get these mixed - somebody please post the correction.

File Descripters vs. File Handles - 

Applies specificly to DOS (MS-DOS, IBM-DOS, etc.) based applications.
File Descripters were a carry over from CP/M - when a program needed to 
open a file, it created a block of memory in it's own data area which 
contained the necessary information about the file.  - Most importantly,
was the location of the file.

In contrast, File Handles are more "true" to the nature of the OS, because
instead of forcing the program to track info about the file it is using, it
merely requests that the OS open the file and give it a "handle".  The OS
is then responsible for all the details of file maintenance (knowing where
the file is, etc..)  The program only needs to request that the OS perform
some function on the file attached to some specific "handle".

File handles are the better way to go.  When hard disks were 10Mb and had a
12bit FAT table, the machine required 1 word (2 bytes) to contain the info
in the file descripter.  When DOS 3.0 showed up and hard disks could become
larger (20Mb+) the FAT table became 16bits and the 1 word of storage in
the file descripter was still sufficient to handle the job.  Then DOS 4.0
showed up and the fat table format increased beyond the ability of the 
file descripter to safely track files which went beyond the 32Mb location
on the disk.  (This is why you should run SHARE on disks with > 32Mb 
partition sizes - SHARE intercepts these old programs still using file
descripters and helps them find their data - without SHARE, your program
could read or write data at an incorrect location.)

If you rely on handles - (IBM stated this YEARS ago), you will never need to
worry about how your program will perform when operating systems are 
upgraded.

Hope this helps.

	-Tim

  ---------------------------------------------------------------------------
	  In real life:  Tim Campbell - Electronic Data Systems Corp.
     Usenet:  campbell at dev8.mdcbbs.com   @ McDonnell Douglas M&E - Cypress, CA
       also:  tcampbel at einstein.eds.com  @ EDS - Troy, MI
 CompuServe:  71631,654	 	         Prodigy:  MPTX77A
 P.S.  If anyone asks, just remember, you never saw any of this -- in fact, I 
       wasn't even here.



More information about the Comp.lang.c mailing list