# PXFOPEN

POSIX Subroutine: Opens or creates a file.

## Module

USE IFPOSIX

CALL PXFOPEN (path,ilen,iopenflag,imode,ifildes,ierror)

path | (Input) Character. The path of the file to be opened or created.
ilen | (Input) INTEGER(4). The length of path string.
iopenflag | (Input) INTEGER(4). The flags for the file. (For possible constant names that can be passed to PXFCONST or IPXFCONST, see below.)
imode | (Input) INTEGER(4). The permissions for a new file. This argument should always be specified when iopenflag=O_CREAT; otherwise, it is ignored. (For possible permissions, see below.)
ifildes | (Output) INTEGER(4). The returned file descriptor for the opened or created file.
ierror | (Output) INTEGER(4). The error status.

If successful, ierror is set to zero; otherwise, an error code.

For iopenflag, you should specify one of the following constant values:

- O_RDONLY (read only)

- O_WRONLY (write only)

- O_RDWR (read and write)

In addition, you can also specify one of the following constant values by using a bitwise inclusive OR (IOR):

Value | Action
--- | ---
O_CREAT | Creates a file if the file does not exist.
O_EXCL | When used with O_CREAT, it causes the open to fail if the file already exists. In this case, a symbolic link exists, regardless of where it points to.
O_NOCTTY1 | If path refers to a terminal device, it prevents it from becoming the process's controlling terminal even if the process does not have one.
O_TRUNC | If the file already exists, it is a regular file, and imode allows writing (its value is O_RDWR or O_WRONLY), it causes the file to be truncated to length 0.
O_APPEND | Opens the file in append mode. Before each write, the file pointer is positioned at the end of the file, as if with PXFLSEEK.
O_NONBLOCK (or O_NDELAY)1 | When possible, opens the file in non-blocking mode. Neither the open nor any subsequent operations on the file descriptor that is returned will cause the calling process to wait. This mode need not have any effect on files other than FIFOs.
O_SYNC | Opens the file for synchronous I/O. Any writes on the resulting file descriptor will block the calling process until the data has been physically written to the underlying hardware.
O_NOFOLLOW1 | If path is a symbolic link, it causes the open to fail.
O_DIRECTORY1 | If path is not a directory, it causes the open to fail.
O_LARGEFILE1 | On 32-bit systems that support the Large Files System, it allows files whose sizes cannot be represented in 31 bits to be opened.
O_BINARY2 | Opens the file in binary (untranslated) mode.
O_SHORT_LIVED2 | Creates the file as temporary. If possible, it does not flush to the disk.
O_TEMPORARY2 | Creates the file as temporary. The file is deleted when last file handle is closed.
O_RANDOM2 | Specifies primarily random access from the disk.
O_SEQUENTIAL2 | Specifies primarily sequential access from the disk.
O_TEXT2 | Opens the file in text (translated) mode. 3
1L*X only 2W*S 2W*S 3For more information, see "Text and Binary Modes" in the Visual C++* programmer's guide.

Argument imode specifies the permissions to use if a new file is created. The permissions only apply to future accesses of the newly created file. The value for imode can be any of the following constant values (which can be obtained by using PXFCONST or IPXFCONST):

Value | Description
--- | ---
S_IRWXU | 00700 user (file owner) has read, write and execute permission.
S_IRUSR, S_IREAD | 00400 user has read permission.
S_IWUSR, S_IWRITE | 00200 user has write permission.
S_IXUSR, S_IEXEC | 00100 user has execute permission.
S_IRWXG1 | 00070 group has read, write and execute permission.
S_IRGRP1 | 00040 group has read permission.
S_IWGRP1 | 00020 group has write permission.
S_IXGRP1 | 00010 group has execute permission.
S_IRWXO1 | 00007 others have read, write and execute permission.
S_IROTH1 | 00004 others have read permission.
S_IWOTH1 | 00002 others have write permission.
S_IXOTH1 | 00001 others have execute permission.
1L*X only

## Example

The following call opens a file for writing only and if the file does not exist, it is created:

    call PXFOPEN( "OPEN.OUT", &
                   8, &
                   IOR( IPXFCONST(O_WRONLY), IPXFCONST(O_CREAT) ), &
                   IOR( IPXFCONST(S_IREAD), IPXFCONST(S_IWRITE) ) )

Parent topic: POSIX* Library Routines

## See Also

PXFCLOSE
IPXFCONST
PXFCONST