Syntax
#include <sys/types.h>
#include <fcntl.h>
int fcntl(int descriptor,
int command,
...)
|
The fcntl() function is used to obtain or change the attributes of a file or socket descriptor.
Parameters
Figure 1-1. fcntl() Commands Supported by Sockets
| Command | Description |
|---|---|
| F_DUPFD | Duplicate the descriptor. |
| F_GETFL | Return status flags for the descriptor. |
| F_SETFL | Set status flags for the descriptor. |
| F_GETOWN | Return the process ID or process group ID that is set to receive the SIGIO (I/O is possible on a descriptor) and SIGURG (urgent condition is present) signals. |
| F_SETOWN | Set the process ID or process group ID that is to receive the SIGIO and SIGURG signals. |
| F_GETFD | Return the descriptor flags for descriptor. Descriptor flags are associated with a single descriptor and do not affect other descriptors that refer to the same file. |
| F_SETFD | Set the descriptor flags for descriptor. Descriptor flags are associated with a single descriptor and do not affect other descriptors that refer to the same file. |
Figure 1-2. Commands Used by the ... Parameter
| Command | Argument Description | ||||
|---|---|---|---|---|---|
| F_DUPFD | The minimum value that the duplicated descriptor can assume. | ||||
| F_SETFL | Status flags that are to be set for the descriptor.
The flag value is obtained by performing an OR operation
on one or more of
the following constants:
| F_SETOWN | Process ID or process group ID that is to receive the SIGIO and SIGURG signals. A positive value specifies a process ID and a negative value specifies a process group ID. | F_SETFD | Descriptor flags to set. See for a description of valid descriptor flags. |
Return Value
Possible values returned by fcntl() are:
Error Conditions
When fcntl() fails, errno can be set to one of the following:
A given file descriptor or directory pointer is not valid for this operation. The specified descriptor is incorrect, or does not refer to an open file.
A parameter passed to this function is not valid.
A physical I/O error occurred.
A referenced object may be damaged.
An attempt was made to open more files than allowed by the value of OPEN_MAX. The value of OPEN_MAX can be retrieved using the sysconf() function.
The process has more than OPEN_MAX descriptors already open (see the sysconf() function).
The operation failed because of an unknown system state. See any messages in the job log and correct any errors that are indicated, then retry the operation.
Error Messages
Usage Notes
Related Information
| Top | Sockets APIs | APIs by category |
| [Information Center Home Page | Feedback ] | [Legal | AS/400 Glossary] |