Open for shared access a file associated with a given descriptor
#include <unistd.h>
int sopenfd( int fd,
int oflag,
int sflag );
libc
The sopenfd() function opens for shared access
the file associated with the file descriptor, fd.
The access mode, oflag, must be equal to or more restrictive than the access mode of the source fd.
The oflag argument specifies how the file is to be opened,
and is a combination of the following bits:
- O_RDONLY
- Permit the file to be only read.
- O_WRONLY
- Permit the file to be only written.
- O_RDWR
- Permit the file to be both read and written.
- O_APPEND
- Cause each record that is written to be written at the end
of the file.
- O_TRUNC
- Causes the file to be truncated to contain no data when the file
exists; has no effect when the file doesn't exist.
The sflag argument specifies how the file is to be shared, and
is a combination of the following bits:
- SH_COMPAT
- Set compatibility mode.
- SH_DENYRW
- Prevent read or write access to the file.
- SH_DENYWR
- Prevent write access of the file.
- SH_DENYRD
- Prevent read access to the file.
- SH_DENYNO
- Permit both read and write access to the file.
Note that:
openfd( fd, oflag );
is the same as:
sopenfd( fd, oflag, SH_DENYNO );
The file descriptor, or -1 if an error occurs
(errno is set).
- EBADF
- Invalid file descriptor fd.
- EACCES
- The access mode specified by oflag isn't equal to or more restrictive
than the access mode of the source fd.
- EBUSY
- Sharing mode (sflag) was denied due to a conflicting open.
Unix
Safety: | |
Cancellation point |
Yes |
Interrupt handler |
No |
Signal handler |
Yes |
Thread |
Yes |
openfd()