previous next top contents index framed top this page unframed
Figure 32–30. close
| BOOLEAN PROCEDURE close (MODIFIES POINTER(file) f; OPTIONAL BITS closeBits; PRODUCES OPTIONAL STRING msg); |
close closes (and optionally deletes) a file.
f is closed according to directives in closeBits, and then set to NULLPOINTER. The record to which f points is not disposed; if it is desired to dispose the file record, it must be done explicitly.
close returns FALSE if and only if an error occurred while closing the file. If an error occurs, the msg parameter is set to a message describing the error.
The only valid predefined bits constants for closeBits are delete and errorOK. If delete is specified, it indicates that the file should be deleted. The delete bit can also be specified to open (Section 43.5), in which case the file is deleted when closed regardless of whether the delete bit is specified to close.
The errorOK bit suppresses an error message if delete is specified and the file cannot be deleted.
A file that was opened at some point during program execution should always be closed before execution is complete. When MAINSAIL exits normally, it automatically closes all files that are open at the end of program execution; however, closing a file may free up resources (e.g., memory or operating-system-dependent file handles) associated with an open file, so it is best to close a file as soon as it is no longer needed.
Closing cmdFile or logFile has the effect of reopening it to TTY.
Example 32–31. Use of close
| POINTER(dataFile) f; ... open(f,"Input file: ",create!random!output!prompt); ... close(f,delete); # never again need to do I/O to f |
MAINSAIL Language Manual, Section 32.31