basic.%open
Opens a Unix file for reading or writing.
Syntax
file.descriptor=%open(string, oflag {, mode })
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.
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
See Also
User Comments
What do you think?
Share your experience or ask a question by using the form below.
Login to leave your comments.
