Go to the previous, next section.

Independent Channels

When you open channels (streams or descriptors) separately on a seekable file, each channel has its own file position. These are called independent channels.

The system handles each channel independently. Most of the time, this is quite predictable and natural (especially for input): each channel can read or write sequentially at its own place in the file. However, if some of the channels are streams, you must take these precautions:

If you do output to one channel at the end of the file, this will certainly leave the other independent channels positioned somewhere before the new end. If you want them to output at the end, you must set their file positions to end of file, first. (This is not necessary if you use an append-type descriptor or stream; they always output at the current end of the file.) In order to make the end-of-file position accurate, you must clean the output channel you were using, if it is a stream. (This is necessary even if you plan to use an append-type channel next.)

It's impossible for two channels to have separate file pointers for a file that doesn't support random access. Thus, channels for reading or writing such files are always linked, never independent. Append-type channels are also always linked. For these channels, follow the rules for linked channels; see section Linked Channels.

Go to the previous, next section.