Record-oriented I/O is possible for SAM, ISAM and PAM files.
When the fopen() and freopen() functions are called, the file must always be opened in binary mode and with the option type=record.
With the creat() or freopen() functions, the file must always be opened in binary mode and the specification of O_RECORD.
I/O functions that read or write characters or strings (up to \n) cannot be used for recordoriented input/output.
Available I/O functions
The following functions are available for processing files with stream I/O:
| Open |
| Close |
| Read |
| Write |
| Set file position to determined location |
| Set file position to start/end of file |
| Set file position to start of file |
| Explicitly positioning in an ISAM file |
| Delete a record in an ISAM file |
In addition, the following functions for file processing and error handling can be used unchanged:
feof(), ferror(), clearerr(), unlink(), remove(), rename()
All I/O functions not listed here are unavailable for record-oriented input/output and will be rejected with an error return value.
It should be noted, however, that no checks are performed for the two macros getc() and putc() for performance reasons. If these macros are used on files with record-orientedI/O, the behavior is undefined.
Processing a file with record-oriented and stream-oriented I/O
Files created for record-oriented I/O can be opened for stream-oriented I/O and vice versa. However, stream-oriented I/O does not support all the file attributes that are possible for record-oriented I/O.
FCBTYPE of a new file to be created
The FCBTYPE of a new file to be created can be defined as follows:
Specification in an
ADD-FILE-LINKcommand and use of theLINKname in thefopen()orfreopen()functionSpecification of the
forgparameter in thefopen()orfreopen()function:forg=seq: a SAM file is created.forg=key: an ISAM file is created.
The following restrictions apply to the FCBTYPE of a file and the entries for fopen() and freopen():
If
type=recordis specified, theFCBTYPEof the file must be SAM, PAM or ISAM.If
forg=seqis specified, theFCBTYPEof the file must be SAM or PAM.If
forg=keyis specified, theFCBTYPEof the file must be ISAM.The append mode "a" is not allowed for ISAM files. The position is determined by the key in the record.
The following restrictions apply to the FCBTYPE of a file and the entries for creat() and open():
If
O_RECORDis specified the file must haveFCBTYPESAM, PAM or ISAM.
Multiple keys for ISAM files
By default, multiple keys are not permitted for ISAM files. They may, however, be used if DUP-KEY=Y is specified in an ADD-FILE-LINK command.