Nios® V Processor Software Developer Handbook

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

16.1.1.75. ioctl()

Prototype

int ioctl (int fd, int req, void* arg)

Commonly Called By

C/C++ programs

Device drivers

Thread-safe

See description.

Available from ISR

No.

Include

<sys/ioctl.h>

Description

The ioctl() function allows application code to manipulate the I/O capabilities of a device driver in driver-specific ways. This function is equivalent to the standard UNIX ioctl() function. The input argument fd is an open file descriptor for the device to manipulate, req is an enumeration defining the operation request, and the interpretation of arg is request specific.

For file subsystems, ioctl() is wrapper function that passes control directly to the appropriate device driver’s ioctl() function (as registered in the driver’s alt_dev structure).

For devices, ioctl() handles TIOCEXCL and TIOCNXCL requests internally, without calling the device driver. These requests lock and release a device for exclusive access. For requests other than TIOCEXCL and TIOCNXCL, ioctl() passes control to the device driver’s ioctl() function.

Calls to ioctl() are thread-safe only if the implementation of ioctl() provided by the driver that is manipulated is thread-safe.

Valid values for the fd parameter are: stdout, stdin, and stderr, or any value returned from a call to open().

Return

The interpretation of the return value is request specific. If the call fails, errno is set to indicate the cause of the error.