Specifications

fcntl()
Prototype
int fcntl(int fd, int cmd)
Commonly Called By
C/C++ programs
Thread-safe
No.
Available from ISR
No.
Include
<unistd.h>
<fcntl.h>
Description
The fcntl() function is a limited implementation of the standard fcntl() system call, which can change
the state of the flags associated with an open file descriptor. Normally these flags are set during the call to
open(). The main use of this function is to change the state of a device from blocking to nonblocking (for
device drivers that support this feature).
The input argument fd is the file descriptor to be manipulated. cmd is the command to execute, which can
be either F_GETFL (return the current value of the flags) or F_SETFL (set the value of the flags).
Return
If cmd is F_SETFL, the argument arg is the new value of flags, otherwise arg is ignored. Only the flags
O_APPEND and O_NONBLOCK can be updated by a call to fcntl(). All other flags remain unchanged. The
return value is zero on success, or –1 otherwise.
If cmd is F_GETFL, the return value is the current value of the flags. If an error occurs, –1 is returned.
In the event of an error, errno is set to indicate the cause.
Related Information
fstat() on page 14-55
ioctl() on page 14-73
isatty() on page 14-74
lseek() on page 14-64
open() on page 14-66
read() on page 14-68
stat() on page 14-60
write() on page 14-69
newlib Library Documentation
NII5V2
2015.05.14
fcntl()
14-57
HAL API Reference
Altera Corporation
Send Feedback