basic.%open

C Function/BASIC Program, Releases: AP/Unix

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

Command Name Type Description
basic.cfunc Definition can be called from a Pick/BASIC program or subroutine in AP/DOS and AP/Unix implementations using a syntax similar to that of normal C.
basic.%close C Function Closes a Unix file.
basic.%read C Function Reads from a Unix file.
basic.%write C Function Writes to a Unix file.
basic.%whex C Function Writes to a Unix file, converting into binary.
basic.%rdhex C Function Reads a Unix file and translates to hexadecimal.
basic.cfunction Definition Declare a list of C functions.
basic.%ttyname C Function Returns a pointer to a terminal name.
basic.%unlink C Function Removes a directory entry.
basic.%fsize C Function Gets the size of a file.
basic.%lseek C Function Sets Unix file pointer.

User Comments

What do you think?

Share your experience or ask a question by using the form below.

Login to leave your comments.