tpf_open–Perform a POSIX open using z/TPF-specific parameters

This function extends a normal POSIX open by allowing z/TPF-specific parameters to be specified.

Last updated

  • Changed for PUT10 (information only; no code change).
  • Added for PUT00.

Format

#include <tpf/tpfio.h>
#include <fcntl.h>
int tpf_open(const char *path, int flags, mode_t mode, struct IfileAttribute 
             *attr, ...);
path
A pointer to a null-terminated character string that defines the path to the file to be opened.
flags
Specifies file open option flags that indicate the processing options for the opened file. See open: Open a file for a list of the valid POSIX open options.
mode
Specifies the mode value to assign to the new file if the file does not exist already and O_CREAT is specified. If O_CREAT was not specified, specify 0 for this parameter. See open: Open a file for the valid mode values.
attr
Specifies a pointer to the file attribute data structure to be used to pass extended attributes to the file. If this parameter is not required, specify NULL.

Normal return

If successful, tpf_open returns a file descriptor greater than or equal to zero.

Error return

If an error occurred, a value of -1 will be returned and errno is set to one of the following values:
ENOTDIR
A component of the path prefix is not a directory.
ENAMETOOLONG
A component of a path name exceeded 255 characters, or an entire path name exceeded 1023 characters.
ENOENT
One of the following occurred:
  • O_CREAT is not set and the named file does not exist.
  • A component of the path name that must exist does not exist.
EACCES
One of the following occurred:
  • Search permission is denied for a component of the path prefix.
  • The required file permissions for reading, writing, or both are not set.
  • O_CREAT is specified, the file does not exist, and the directory in which it is to be created does not permit writing.
ELOOP
Too many symbolic links were found when translating the path name.
EISDIR
The named file is a directory and the arguments specify that it is to be opened for writing.
EROFS
The named file resides on a read-only file system and the file is to be modified.
EMFILE
The process already has reached its limit for open file descriptors.
EMLINK
O_NOFOLLOW was specified and the target is a symbolic link.
ENXIO
One of the following occurred:
  • The named file is a character special or block special file, and the device associated with this special file does not exist.
  • The named file is a fifo, no process has it opened for reading, and the arguments specify that it is to be opened for writing.
EOPNOTSUPP
One of the following occurred:
  • O_SHLOCK or O_EXLOCK is specified, but the underlying file system does not support locking.
  • The named file is a special file mounted through a file system that does not support access to it.
EWOULDBLOCK
O_NONBLOCK and either O_SHLOCK or O_EXLOCK are specified and the file is locked.
ENOSPC
One of the following occurred:
  • O_CREAT is specified, the file does not exist, and the directory in which the entry for the new file is being placed cannot be extended because there is no space left on the file system containing the directory.
  • O_CREAT is specified, the file does not exist, and there are no free i-nodes on the file system on which the file is being created.
EIO
An I/O error occurred while making the directory entry or allocating the i-node for O_CREAT.
EFAULT
The path argument points outside the allocated address space for the process.
EEXIST
O_CREAT and O_EXCL were specified and the file exists.
EINVAL
An attempt was made to open a descriptor with an illegal combination of O_RDONLY, O_WRONLY, and O_RDWR.

Programming considerations

None.

Examples

The following example opens or creates and opens a user-specified file.
#include <tpf/tpfio.h>
⋮
     mode_t  mode = 0777;
     int     flags = O_RDWR|O_CREAT;
     char    path{256};
     struct IfileAttribute  attr;
       memset(&attr, 0x00, sizeof(struct IfileAttribute));
       attr->service_class = class0;
       sprintf(path, "/usr/user1/%s"
         input_fileName);
       fd = tpf_open(path, flags, mode, &attr);       

Related information