Accessing Files Programmer's Guide (32650-90885)

Chapter 6 105
Closing a File
Closing a Disk File
Closing a Disk File
The following examples show how you use the FCLOSE intrinsic to close a disk file:
"Closing a New Disk File as Permanent" shows an example of an FCLOSE call that
closes the file opened in Example 5-1.
"Closing a Permanent Disk File" shows an example of an FCLOSE call that closes the file
opened in Example 5-2.
Closing a new disk file as permanent
Example 6-1 is an HP Pascal/XL code segment containing an HPFOPEN call that opens a
new file, and an FCLOSE intrinsic call that changes the disposition of the file to permanent
prior to closing it. (Refer to Example 5-1 for details on this HPFOPEN call.)
In Example 6-1, there is a disposition conflict between the FCLOSE call and the HPFOPEN
call that opened the file identified by file_num:
The
disposition
parameter of FCLOSE specifies that the file is to be closed as a
permanent file.
The
final disposition option
of the HPFOPEN call specifies that the file should be
closed as a temporary file.
The
disposition
parameter of FCLOSE takes precedence over the final disposition option
of HPFOPEN because the integer value of FCLOSE's
disposition
(1) is a smaller positive
value than that of HPFOPEN's
final disposition option
(2).
Example 6-1. Closing a New Disk File as Permanent
.
.
.
save_temp := 2;
HPFOPEN(file_num, status,
formal_designator_option, file_name, {HPFOPEN
formaldesignator option
}
record_size_option, line_len, {HPFOPEN
record size option
}
final_disp_option, save_temp, {HPFOPEN
final disp option
}
ASCII_binary_option, ascii {HPFOPEN
ASCII/binary option
}
);
.
.
.
error := 1;
disposition := 1; {close file as a permanent file }
security_code := 0; {No additional restrictions }
FCLOSE ( file_num, {file_num returned by HPFOPEN }
disposition, {close file with permanent disposition }
security_code {no additional restrictions are added }
);
if ccode = error then handle_file_error (file_num, 0)
.