Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!usc!zaphod.mps.ohio-state.edu!caen!ox.com!yale!cmcl2!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: file descriptor vs file handle Message-ID: <15331@smoke.brl.mil> Date: 26 Feb 91 19:56:48 GMT References: <90361.145855COS99291@ufrj.bitnet> <27C9CB35.5F7@wilbur.coyote.trw.com> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 24 In article <27C9CB35.5F7@wilbur.coyote.trw.com> cwong@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.