Accessing Files Programmer's Guide (32650-90885)

Chapter 5 93
Opening a File
Which to Use: HPFOPEN or FOPEN
When the HPFOPEN/FOPEN intrinsic is executed, it returns to your program a file number. If
the file is opened successfully, the file number returned is a positive integer. At this point,
the file is ready to be accessed with system intrinsics (for example, FREAD or FWRITE). If the
file cannot be opened, the file number returned is zero, and the intrinsic returns an error
condition.
If your process issues more than one HPFOPEN/FOPEN call for the same file before it is
closed, this results in multiple, logically separate accesses of that file, and MPE/iX returns
a unique file number for each such access. Also, MPE/iX maintains a separate logical
record pointer (indicating the next sequential record to be accessed) for each access where
you did not request or permit the
multiaccess option
at HPFOPEN/FOPEN time.
Which to Use: HPFOPEN or FOPEN
The HPFOPEN intrinsic is the recommended intrinsic for creating and opening files on an
MPE/iX-based computer system. HPFOPEN is designed to be more flexible and extendible
than the FOPEN intrinsic. In addition, HPFOPEN's available options are a superset of the
options available through FOPEN. For example, mapped access is available through
HPFOPEN but not through FOPEN.
NOTE
One HPFOPEN option, the
file privilege option
, when used to set a new
file's privilege level to other than 3 (least-privileged, or user level), disallows
all subsequent access of that file by the FOPEN intrinsic. (For compatibility
reasons, FOPEN can only access a file whose file privilege level is three.)
You should use the FOPEN intrinsic only if you are planning to migrate your application
between MPE/iX-based systems and MPE V/E-based systems. HPFOPEN is not supported on
an MPE V/E-based system.
The examples in this chapter illustrate the use of the HPFOPEN intrinsic. The HPFOPEN
intrinsic uses an
itemnum, item
pair convention for optional parameter passing. The
itemnum
and
item
parameters are paired, where the
n
th
itemnum
is immediately followed
in the parameter list by the
n
th
item
. The
itemnum
parameter passes by value an integer
that the intrinsic uses to define the meaning and expected data type of the value passed by
reference in the corresponding
item
parameter.
For details on HPFOPEN and FOPEN parameters, refer to the respective intrinsics
descriptions in the MPE/iX Intrinsics Reference Manual.
Opening a Disk File
Disk files are files residing on volumes (disk packs). Disk files are immediately accessible
by the system and potentially shareable by several jobs or sessions at the same time. The