NAME

bopen - open a BASIC file

SYNOPSIS

#include <basic/string.h>

bopen(fn, name, mode, type, len)
short fn;
struct string *name, *mode;
int type;
short len;

DESCRIPTION

Bopen opens the file given by the string pointed to by name, and associates it with the file number fn.  If mode is null, the method of access is given by type; otherwise, it is given by the first character of the string pointed to by mode.  This character may be either upper or lower case. 

            Mode      Type      Method of Access
 
I0Sequential Input
O1Sequential Output
A2Sequential Output, Appending
R3Random I/O,
Two-Way Communication

If a disk file is being opened for random I/O, len is taken as the length of the buffer.  If len is zero, then the buffer length is IBMSECTOR (see io(inc)).  Len is interpreted as an unsigned value: a negative len yields a buffer length of 65536 - len.  For a tty, len is the number of seconds to wait for input.  If len is zero, the wait is indefinite. 

If name begins with the characters “pipe:”, a process is created with the shell command (see sh(1)) given by the remainder of name and a pipe (see pipe(2)) is created to the standard input and/or output of the process. 

A pipe or tty may be open for two-way communication allowing both reading and writing. 

Bopen creates an output file if it does not exist.  If the file is a tty, its original state is recorded and changed if appropriate (see initty(io)).  If the file is not a tty, a buffer is allocated.  If the file is a disk file open for random I/O and a buffer of adequate length was allocated previously for the same purpose using the same fn, the buffer is reused.  In any case, biotab[fn] is initialized and contains all the information necessary for maintaining the file (see io(inc)). 

This function implements the OPEN statement. 

SEE ALSO

io(inc), initty(io), bclose(io)
open(stmt)
sh(1), pipe(2) in the UNIX Programmer’s Manual

DIAGNOSTICS

Error 52 (Bad file number) if fn is out of range. 

Error 54 (Bad file mode) if mode is not null and does not begin with the appropriate character. 

Error 55 (File already open) if a file is already open using fn

from The Basmark QuickBASIC Programmer’s Manual by Lawrence Leinweber