Developer Guide and Reference

ID 767251
Date 10/31/2024
Public
Document Table of Contents

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.

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.

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) ) )