C/C++ Programmer's Guide (G06.27+, H06.08+, J06.03+)

models, are the ANSI model, which uses FILE pointers to identify files, and the alternate model,
which uses file descriptors for this purpose. The ANSI model is the same for the Guardian and
OSS environments. For TNS C, the alternate model is different between the Guardian and OSS
environments. In the Guardian TNS environment, the alternate model is an HP extension to the
ISO/ANSI C standard. The OSS TNS environment, however, and in both the OSS and Guardian
native environments use the model based on the XPG4 specification. (The Guardian native
environment permits access to the alternate model.)
The discussion presented later in this section describes the alternate model defined by HP for the
Guardian TNS environment. For more details on the alternate model in both the OSS TNS and
OSS native environments and in the Guardian native environment, see the reference pages for the
alternate model I/O functions or an appropriate edition of the Open System Services Library Calls
Reference Manual.
If no combination of file-reference model and logical file type provides the I/O services you require,
call Guardian system procedures directly to perform specialized I/O functions. To find out how to
access these procedures, see Chapter 3: Interfacing to Guardian Procedures and OSS Functions.
Logical File Types
Regardless of the file-reference model you use, specify the logical file type of a physical file when
you open the physical file. When selecting logical type to use, consider two factors:
1. The logical types best matches the way you want to interpret the data in the physical file
2. 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, 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 10: Buffer Sizes .
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).
Table 10 Buffer Sizes
Maximum Length of Buffer in BytesFile Type
239Terminals
239EDIT files
256C file accessed as text-type logical file
72 Using the C Run-Time Library