NAME open - open an existing file for reading, writing, or both SYNOPSIS fd = open (name, access) character name(FILENAMESIZE) integer access filedes fd - returned as file descriptor/ERR DESCRIPTION Open opens the file whose name is contained in "name" for I/O according to the value of "mode", which may be READ, WRITE, READWRITE, or APPEND. If the file exists and can be opened according to "mode", open returns a file descriptor. If the file cannot be opened, ERR is returned. After a file is opened, it is positioned at the beginning, unless APPEND access is requested, in which case the file is prepared for extension. Opening the same file for reading more than once is permissible and works correctly. However, on many systems a file may be opened only once in WRITE, APPEND, or READWRITE mode. There is generally a limit to the number of files that can be opened simultaneously. This number is specified by the definition MAXOFILES in the general symbol definition file. IMPLEMENTATION Open attaches an existing file to a running program and associates the external file name with an internal identifier which is then usable by the program. The file is opened for I/O according to the value of "mode", where mode may be READ, WRITE, READWRITE, or APPEND. "Name" is passed as an ascii character array, stored one character per array element. The access modes READ, WRITE, READWRITE, and APPEND are global symbols defined in the standard definitions file. Open does whatever manipulations are necessary to allow reading and/or writing to the file. An internal descriptor (usually an integer) is assigned to the file and subsequently used when calling other primitives such as close, getch, putch, getlin, and putlin. 'Open' should be able to open a channel to the teletype in responce to the filenames defined by TERMINAL_IN and TERMINAL_OUT. It also might be taught to respond to other device names where appropriate. Open may have to set up an internal I/O buffer for the file. It may also have to determine the file's type (teletype, character file, binary file). Information about the file's type and teletype characteristics (yes or no) is generally maintained and made available to the user via "isatty" and possibly other file characteristics primitives. Open is sometimes taught to read characters of ascii type as well as local character type (if not ascii). Translation of characters from local to ascii is done when the characters are passed to getch and getlin. Opening a fresh instance of an already opened file is permissible and does not affect the position of the file as accessed by subsequent or previous calls. There is generally a limit to the maximum number of files open at any one time. 10-15 is a common range. READWRITE access may cause problems, or even be impossible on many systems. The only tool which needs this access is the editor. If necessary, READWRITE access may be implemented by opening the file twice--once at READ and once at WRITE access. SEE ALSO create, close, remove, getch, putch, readf, writef, seek, note, isatty DIAGNOSTICS Open returns ERR if the file does not exist, if one of the necessary directories (if any) does not exist or is unreadable, if the file is not readable/writeable, or if too many files are open.