basic.%open C Function/BASIC Program

basic.%open

Command basic.%open C Function/BASIC Program
Applicable release versions: AP/Unix
Category BASIC Program (486)
Description opens the Unix file specified by "string" and sets the file status flags according to the value of "oflag".

Files opened by %open() are closed automatically when the Pick/BASIC programs terminates.

Valid values of "oflag" are defined in the include fcntl.h. Combinations of the modes are obtained by adding several flags together from the following list:

O$RDONLY Opens for reading only.

O$WRONLY Opens for writing only.

O$RDWR Opens for reading and writing.

O$NDELAY Non blocking I/O. The effect of this flag varies depending on the type of the file. See the Unix Programmer's Reference Manual.

O$APPEND Moves the file pointer to the end of the file.

O$SYNC Sync writes.

O$CREAT If the file exists, this flag has no effect. Otherwise, owner ID and group ID are set and the mode of the file is set according to the value of mode modified as follows: all bits in the file mode creation mask of the process are cleared and the sticky bit is cleared.

O$TRUNC If the file exists, its length is set 0.

O$EXCL If O$EXCL and O$CREAT are set, open will fail if the file exists.

The file descriptor is returned as a number or "-1" if an error occurred. System(0) contains the error number.
Syntax file.descriptor=%open(string, oflag {, mode })
Options
Example
include dm,bp,unix.h fcntl.h 
fd=%open( '/usr/pick/fname', O$WRONLY+O$APPEND )
if fd<0 then
  crt 'Cannot open. errno=':system(0)
end
Purpose
Related basic.cfunc
basic.%close
basic.%read
basic.%write
basic.%whex
basic.%rdhex
basic.cfunction
basic.%ttyname
basic.%unlink
basic.%fsize
basic.%lseek