C/C++ Programmer's Guide (G06.25+)
Using the C Run-Time Library
HP C/C++ Programmer’s Guide for NonStop Systems—429301-008
4-3
Logical File Types
Logical File Types
Regardless of the file-reference model you use, you specify the logical file type of a
physical file when you open the physical file. When selecting which logical type to use,
you must consider two factors:
1. Which of the logical types best matches the way you want to interpret the data in
the physical file
2. Whether the logical type chosen in Step 1 is available for the given physical file
type
The next two subsections describe how the two logical file types interpret and buffer
data.
Binary-Type Logical Files
The C run-time library interprets a binary-type logical file as a sequence of arbitrary
byte values. It does not translate data on input or output. Consequently, you control the
structure, content, and interpretation of a binary-type logical file.
Text-Type Logical Files
The C run-time library interprets a text-type logical file as a sequence of lines
containing ASCII text. Terminating each line of text is a newline character \n. In
addition, tab characters are converted to an appropriate number of spaces.
Both of the file-reference models perform line buffering of text files. However, both
models enable you to disable this buffering. In the ANSI model, the setnbuf()
function provides this service; in the alternate model, the fcntl() function does it.
Line buffering implies that data is buffered until a newline is transferred. However, the
C run-time library also flushes the buffer when:
•
The buffer becomes full. The maximum buffer sizes are listed in Table 4-1, Buffer
Sizes, on page 4-4.
•
You explicitly flush the buffer (using fflush() or fcntl()).
•
You make a call to fclose() or exit().
•
You make an input request of a nondisk file without flushing a series of output
requests (by sending a newline or flushing the buffer).