Accessing Files Programmer's Guide (32650-90885)

56 Chapter2
Creating A File
Specifying a Record Format
Specifying a Record Format
A file can contain records written in only one of three formats: fixed-length,
variable-length, and undefined-length. You can specify the format that you want for your
records, either with the HPFOPEN/FOPEN intrinsic or the MPE/iX BUILD or FILE commands.
Files residing on disk or magnetic tape may contain records in any of the three formats.
For files on other devices, the file system overrides any specifications that you supply, and
treats the records as undefined-length records.
Fixed-length records
When you create a file and request fixed-length records, all the records in the file will be
the same size. The file system knows how much space has been allocated for each record,
and that all of the space is to be available for data.
Figure 2-2. depicts a file with fixed-length records. A record size of
n
bytes has been
specified. Note that each record is the same size and contains the same amount of
information.
Figure 2-2. Fixed-Length Records
Variable-length records
There may be a time when you want a disk file in which the logical records need not be the
same size. In this case, you can request that the format of the records be variable-length.
The file system knows the size of each logical record because each record is preceded by a
two-byte (16-bit) counter giving the length of the record in bytes; thus, the data for each