Open a path and set connection flags
Synopsis:
#include <fcntl.h>
int open_ext( const char *name,
int oflag,
int mode,
int coflag );
Arguments:
- name
- The pathname of the file that you want to open.
- oflag
- Flags that specify the status and access modes of the file; see
open().
- mode
- The access mode that you want to use for a newly created file.
This argument is used only if you set O_CREAT in oflag.
For more information, see the entry for
struct stat,
and the description of
O_CREAT
the entry for open().
- coflag
- A bitmap of the connection flags you want to set.
The bits currently defined include:
- _NTO_COF_CLOEXEC — close the connection if the
process calls an exec*() function to start a new process.
- _NTO_COF_INSECURE (QNX Neutrino 6.6 or later) — mark the connection as insecure.
The kernel sets this flag on a connection if the client program replaces its process image
(e.g., by calling exec*())
with a setuid or setgid binary.
If this flag is set on a connection, calls to
MsgDeliverEvent()
with an event type of SIGEV_MEMORY or SIGEV_THREAD
fail with an error of EACCES.
In QNX Neutrino 7.0 and later,
the server or client can set this flag if it doesn't trust the program at the other end of the connection,
but only the kernel can clear it.
Currently the flag stays set until the connection is detached.
- _NTO_COF_NOEVENT (QNX Neutrino 7.0 or later) — prevent the server from sending
sigevents over the channel to the client.
Only the client can clear this bit.
- _NTO_COF_REG_EVENTS (QNX Neutrino 7.0.1 or later) — require that the connection
use only registered events; reject the delivery of any
sigevents
that weren't registered as secure events with
MsgRegisterEvent().
- _NTO_COF_UNREG_EVENTS (QNX Neutrino 7.1 or later) — override the OS requirement
that all sigevents be registered, allowing this connection to use registered and unregistered events.
You can use
procnto's
-U option to allow all processes to use registered and unregistered events;
_NTO_COF_UNREG_EVENTS lets you do this for a specific connection.
Note:
Both _NTO_COF_UNREG_EVENTS and procnto's -U option
are temporary measures that weaken security. You should use them only while updating your code to use registered events.
Library:
libc
Use the -l c option to
qcc
to link against this library.
This library is usually included automatically.
Description:
The open_ext() function opens the file named by path,
creating an open file description that refers to the file, and a file
descriptor that refers to the file description.
It then sets the connection flags.
It lets you combine
open()
and
ConnectFlags()
in a single operation.
Returns:
A nonnegative integer representing the lowest numbered unused file descriptor. On a file
capable of seeking, the file offset is set to the beginning of the file.
Otherwise, -1 is returned
(errno is set).
Note:
In
QNX Neutrino, the returned file descriptor is a connection ID
(or
coid) as used by the
QNX Neutrino-specific functions (e.g.,
MsgSend()).
Errors:
- EACCES
- Search permission is denied on a component of the path prefix, or the
file exists and the permissions specified by oflag
are denied, or the file doesn't exist and write permission is denied
for the parent directory of the file to be created.
- EBADFSYS
- While attempting to open the named file, either the file itself or a
component of the path prefix was found to be corrupted.
A system failure—from which no automatic recovery is possible—occurred while
the file was being written to, or while the directory was
being updated. You'll need to invoke appropriate
systems-administration procedures to correct this situation before proceeding.
- EBUSY
- File access was denied due to a conflicting open (see
sopen()).
- EEXIST
- The O_CREAT and O_EXCL flags are set, and the named file exists.
- EINTR
- The operation was interrupted by a signal.
- EINVAL
- The requested synchronized modes (O_SYNC, O_DSYNC, O_RSYNC)
aren't supported (i.e, IOFUNC_PC_SYNC_IO isn't set
in the device's mount configuration).
- EISDIR
- The named file is a directory and the oflag
argument specifies write-only or read/write access, or includes O_CREAT without
O_DIRECTORY.
- ELOOP
- There are too many levels of symbolic links or prefixes, including these cases:
- The flags include O_NOFOLLOW, and the last component of the path is a symbolic link.
- The flags include O_NOSYMLINK, and any component of the path is a symbolic link.
- EMFILE
- All file descriptors available to the process are currently open.
- ENAMETOOLONG
- The length of the name string exceeds PATH_MAX.
- ENFILE
- Too many files are currently open in the system.
- ENOENT
- The O_CREAT flag isn't set, and the named file doesn't exist;
or O_CREAT is set and either the path prefix doesn't exist
or the path argument points to an empty string.
- ENOSPC
- In the directory or filesystem that would contain the new file, there's not enough space available to create a new file
or the maximum limit of files has been reached.
- ENOSYS
- This function isn't implemented for the filesystem underlying the specified path.
- ENOTDIR
- One of the following occurred:
- A component of the path prefix names an existing file that is neither a directory nor a symbolic link
to a directory.
- O_CREAT and O_EXCL aren't specified, the path argument
contains at least one non-slash character and ends with one or more trailing slash characters,
and the last pathname component names an existing file that is neither a directory nor a symbolic link
to a directory
- O_DIRECTORY was specified and the path argument resolves to a
non-directory file.
- ENOTSUP
- The oflag argument includes O_CREAT and O_DIRECTORY.
- ENXIO
- One of the following is true:
- The O_NONBLOCK flag is set, the named file is a FIFO,
O_WRONLY is set, and no process has the file open for reading.
- The media associated with the file (e.g., a CD) has been removed.
- EOVERFLOW
- The named file is a regular file and its size can't be
represented correctly in an object of type off_t.
- EPERM
- The process doesn't have the necessary permissions to connect.
- EROFS
- The named file resides on a read-only filesystem and either
O_WRONLY, O_RDWR, O_CREAT
(if the file doesn't exist), or O_TRUNC is set in the
oflag argument.
- ETXTBSY
- The file is a pure procedure (shared text) file that's currently being executed
and oflag is O_WRONLY or O_RDWR.
Classification:
QNX Neutrino
Safety: |
|
Cancellation point |
Yes |
Interrupt handler |
No |
Signal handler |
Yes |
Thread |
Yes |