PROCEDURE Close(f: File) RAISES {Error}; (* BadFileEC, FailureES *)
Close removes the reference from the specified file handle to the underlying open-file object. Once a file handle has been closed, passing it to any procedure other than Close causes BadFileEC to be raised. Passing a file handle to Close a second time does not cause an exception to be raised (or have any other effect).
Once the last file handle referring to a particular open-file object is closed, the open-file object itself is deleted and the advisory lock held by that open-file object, if any, is released.
Once the last open-file object for a particular file is deleted, the file
itself is closed. This entails deleting the file if all the directory
entries referring to it have been removed, or else clearing its
exclusive-use flag and, if it is a regular file, freeing any disk space
tentatively allocated past the file's current length (see the SetSize
procedure on page ).
A Close is automatically performed when a file handle is garbage-collected or the process holding it terminates, but it is often desirable to perform the Close explicitly to initiate the associated behavior. (For example, closing the read end of a pipe can be detected at the write end of the pipe.)
Taos note: When a file itself is being closed (because the last open-file object referring to it is being closed) but not deleted (because there are still directory entries referring to it) and its data or attributes (other than access time) have been modified, Close schedules the writes necessary to flush the modifications to disk. Unlike EnsureWritten, Close doesn't wait for the writes to complete.
PROCEDURE Dup(f: File): File RAISES {Error}; (* BadFileEC *)
Dup returns another file handle that refers to the same open-file object as does f. The point in doing this is to pass the new file handle to a separate thread or package that can then close it when it is finished with it without affecting the original file handle.
Ultrix note: Unlike the Ultrix dup kernel call, Dup does not create another file descriptor (of which there are a finite number), so it should be considered an inexpensive operation.
PROCEDURE GetDescriptor(d: CARDINAL): File RAISES {}; PROCEDURE GetMaxDescriptor(): CARDINAL RAISES {};
The procedures GetDescriptor and GetMaxDescriptor provide access to the constant array of file handles supplied when the process was created. GetDescriptor returns the d'th file handle, or NIL if the corresponding array element was not set. GetMaxDescriptor returns the largest number i such that GetDescriptor(i) will not return NIL.
CONST StdIn = 0; StdOut = 1; StdErr = 2;
The constants StdIn, StdOut, and StdErr define the indices of the standard input, standard output, and standard diagnostic output passed by shells (see sh(1) and csh(1)) when they start processes.