Returned value
If successful, the value fcntl() returns will depend on the action that was specified.
- Error Code
- Description
- EAGAIN
- The process tried to set a lock with F_SETLK, but the lock is in conflict with a lock already set by some other process on an overlapping part of the file.
- EBADF
- fildes is not a valid open file descriptor; or the
process tried to set a read lock on a file descriptor open for writing
only; or the process tried to set a write lock on a file descriptor
open for reading only; or the socket parameter is not a valid
socket descriptor.
In an F_DUPFD2 operation, the third argument is negative, or greater than or equal to OPEN_MAX, which is the highest file descriptor value allowed for the process.
- EDEADLK
- The system detected the potential for deadlock in a F_SETLKW operation.
- EINTR
- fcntl() was interrupted by a signal during a F_SETLKW operation.
- EINVAL
- In an F_DUPFD operation, the third argument is negative or greater
than or equal to OPEN_MAX, the highest file
descriptor value allowed for the process. The OPEN_MAX value
can be determined using pathconf().
In a locking operation, fildes refers to a file with a type that does not support locking, or the struct flock pointed to by the third argument has an incorrect form.
If an F_CLOSFD operation, the third argument, which specifies the upper limit, is less than filedes but is not equal to -1.
Behavior for sockets: The arg parameter is not a valid flag, or the cmd parameter is not a valid command.
- EMFILE
- In an F_DUPFD operation, the process has already reached its maximum number of file descriptors, or there are no available file descriptors greater than the specified third argument.
- ENOLCK
- In an F_SETLK or F_SETLKW operation, the specified file has already reached the maximum number of locked regions allowed by the system.
- EOVERFLOW
- One of the values to be returned cannot be represented correctly.
The cmd argument is F_GETLK, F_SETLK or F_SETLKW and the smallest or, if l_len is nonzero, the largest offset of any byte in the requested segment cannot be represented correctly in an object of type off_t.
- EPERM
- The operation was F_CLOSFD, but all the requested file descriptors were not closed.