FILE descriptor <-> FILE pointers
Dave Decot
decot at hpisod2.HP.COM
Sat Aug 19 06:07:30 AEST 1989
> 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
More information about the Comp.unix.wizards
mailing list