Nios® V Processor Software Developer Handbook

ID 743810
Date 7/08/2024
Public
Document Table of Contents

16.1.1.56. 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.