Go to the previous, next section.
int fcntl(int fd, int cmd);
int fcntl(int fd, int cmd, long arg);
fd: [in] the file descriptor affected by the call.
cmd: [in] the operation to apply on the file descriptor.
arg: [in] an optionnal argument to the operation.
This call directly applies an operation on a file descriptor. The possible operations are:
F_DUPFD
dup2
. See section dup and dup2
F_GETFD
F_SETFD
F_GETFL
open
).
F_SETFL
O_APPEND
and O_NONBLOCK
. See section creat and open
F_GETLK
l_type
member is set to F_UNLCK
. Otherwise,
arg is modified to describe the lock preventing the set operation.
F_SETLK
F_SETLKW
F_SETLK
but block if the lock can not be set.
F_GETOWN
F_SETOWN
SIGIO
and SIGURG
signals. A
process group is specified by a negative value.
F_GETLK
, F_SETLK
or F_SETLKW
commands, the argument is a pointer to a flock
structure. This
structure has the following layout:
struct flock { short l_type; /* read, write or unlock */ short l_whence; /* how to interpret l_start */ off_t l_start; /* where to begin the locking area */ off_t l_len; /* the lenght of the area to lock */ pid_t l_pid; /* the pid of the task holding the lock: returned by F_GETLK */ };
The l_whence
member has the same meaning as for lseek
.
See section lseek l_type
can take one of the following values:
F_RDLCK
F_WRLCK
F_UNLCK
The system merges adjacent locking regions of the same type and owned by the same task. When a subregion inside a region is unlocked, the region is split in two parts.
On success, it depends on the cmd parameter:
F_DUPFD
F_GETFD
F_GETFL
F_GETOWN
On error, the call returns -1 and errno
is set to one of the
following values:
EINVAL
: for F_DUPFD
, arg is invalid or the
maximum number of opened file descriptor is reached. For F_GETLK
,
specified a lock with F_UNLCK
. Or unlock operation failed.
EBADF
: the file descriptor is invalid, or the task
requested a lock for reading or writing while it does not have the
corresponding read or write access right on the file.
EAGAIN
: impossible to set the lock.
ENOLCK
: impossible to allocate memory for the new lock.
EFAULT
, ERESTARTSYS
.
Go to the previous, next section.