Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wasatch!cs.utexas.edu!sun-barr!apple!motcsd!hpda!hpcupt1!hpisod2!decot From: decot@hpisod2.HP.COM (Dave Decot) Newsgroups: comp.unix.wizards Subject: Re: FILE descriptor <-> FILE pointers Message-ID: <14020074@hpisod2.HP.COM> Date: 18 Aug 89 20:07:30 GMT References: <148@cerc.wvu.wvnet.edu.edu> Organization: Hewlett Packard, Cupertino Lines: 40 > fdopen can be used to convert file descriptor to a FILE pointer > > fileno can be used to convert a FILE pointer to file descriptor > > A file descriptor is returned by open and used by dup, write, read etc > > A FILE pointer is returned by fopen and used fprintf, fscanf , fget* > and printf and scanf (implicitly). There is also some even more unfortunate terminology floating around, regarding the following three things: 1 The thing in the kernel for each group of shared file descriptors that describe the state of the same open file, containing Thing 2 mentioned below, the (O_RDWR ...) mode passed to open(), and the (O_APPEND | O_SYNC | ... ) flags manipulated by open() and fcntl(). 2 The current lseek() position for the file descriptor. 3 The current fseek() position for the standard I/O stream. All three of the above have commonly been referred to as a "file pointer" (not to be confused with "FILE pointer"!). POSIX straightens this all out by using the following terminology: file descriptor Same as always, containing the: file descriptor flags FD_CLOEXEC, etc. open file description The shared thing in the kernel containing the: file access mode O_RDWR, etc. file status flags O_APPEND, etc. file offset Current lseek() position stream Thing referenced by a FILE *, contaning: file position indicator Current fseek() position Whew! Dave