VARKON Version 1.15 1998-01-08
open - Procedure
Opens a file
Description
Used to establish connection with a named file or to create a pipe to another program.
Syntax
open(f, mode, name)
FILE f; STRING mode*2; STRING name*132;
Principal parameters
f - The name of a filevariable to be used for successive operations mode - Type of operations to be allowed on the opened file or pipe R = Read from file W = Write to file (if file exists it is overwritten otherwise it is created) A = Append to file (if no file exists it is created) U = Update (read, write and seek) RP = Read from pipe WP = Write to pipe name - Name of file to open or command to create the pipe
Optional parameters
None.
Examples
FILE f;
open(f, "r" , "/usr/mydir/job.dat") ! Opens a file named job.dat in /usr/mydir for reading only
open(f, "w", "new.dat") ! Creates a new file named new.dat in current directory
open(f, "rp", "cd /usr/mydir;ls") ! Creates a read-pipe to the output of the ls-program
Comments
The codes for mode may be upper or lower case.
open automatically resets the current position within the file to zero.
An attempt to open a file more than once without first closing it is treated as an error. It is also important to close the file before accessing it from other programs.
The iostat function can be used to detect any errors.See also
VARKON Homepage | Index |