Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!dev8n.mdcbbs.com!campbell From: campbell@dev8n.mdcbbs.com (Tim Campbell) Newsgroups: comp.lang.c Subject: Re: file descriptor vs file handle Message-ID: <1991Feb26.101038.1@dev8n.mdcbbs.com> Date: 26 Feb 91 10:10:38 GMT References: <90361.145855COS99291@ufrj.bitnet> <27C9CB35.5F7@wilbur.coyote.trw.com> Organization: McDonnell Douglas M&E, Cypress CA Lines: 52 Nntp-Posting-Host: dev8n Nntp-Posting-User: campbell In article <27C9CB35.5F7@wilbur.coyote.trw.com>, cwong@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@dev8.mdcbbs.com @ McDonnell Douglas M&E - Cypress, CA also: tcampbel@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.