This chapter describes functions for performing low-level input/output operations on file descriptors. These functions include the primitives for the higher-level I/O functions described in I/O on Streams, as well as functions for performing low-level control operations for which there are no equivalents on streams.
Stream-level I/O is more flexible and usually more convenient; therefore, programmers generally use the descriptor-level functions only when necessary. These are some of the usual reasons:
For reading binary files in large chunks.
For reading an entire file into core before parsing it.
To perform operations other than data transfer, which can only be done with a descriptor. (You can use fileno
to get the descriptor corresponding to a stream.)
To pass descriptors to a child process. (The child can create its own stream to use a descriptor that it inherits, but cannot inherit a stream directly.)
Opening and Closing Files | How to open and close file descriptors. |
I/O Primitives | Reading and writing data. |
File Position Primitive | Setting a descriptor's file position. |
Descriptors and Streams | Converting descriptor to stream or vice-versa. |
Stream/Descriptor Precautions | Precautions needed if you use both descriptors and streams. |
Waiting for I/O | How to check for input or output on multiple file descriptors. |
Control Operations | Various other operations on file descriptors. |
Duplicating Descriptors | Fcntl commands for duplicating file descriptors. |
Descriptor Flags | Fcntl commands for manipulating flags associated with file descriptors. |
File Status Flags | Fcntl commands for manipulating flags associated with open files. |
File Locks | Fcntl commands for implementing file locking. |
Interrupt Input | Getting an asynchronous signal when input arrives. |