# %ioctl() function

The %ioctl() function is a general purpose
control function that passes the arguments *request* and *arg* to the device designated by *file.descriptor*.

**For Windows:**Not Supported

## Syntax

```
var = %ioctl(file.descriptor, request, arg)
```

## Description

The format of the arguments
is device-specific. These arguments are usually binary data that must
be kept out of FlashBASIC data space. See the example below.

CAUTION: Extreme care must be exercised when using this function.
The arguments to %ioctl() are dependent on the
system and the UNIX version. Whenever possible, it is preferable to
use the D3 tools to access a device. For example, execute set-baud /dev/tty15,9600 works on all Pick implementations,
while the corresponding UNIX ioctl() function varies
widely.

## Example(s)

```
* Allocate some data
ptr=(char*)%malloc(128)
* Open the terminal and get its termio structure
execute "!exec tty" capturing ttyname
fd=%open(ttyname, o$rdwr)
n=%ioctl(fd, tcgeta, (char*)ptr)
...
* Release data
%free((char*) ptr)
```

## See also

- [%ttyname() function](https://d3codex.com/pickbasic-flashbasic/percent-ttyname-function/)
- [FlashBASIC C functions overview](https://d3codex.com/pickbasic-flashbasic/flashbasic-c-functions-overview/)
- [cfunction statement](https://d3codex.com/pickbasic-flashbasic/cfunction-statement/)

---
Source: https://d3codex.com/pickbasic-flashbasic/percent-ioctl-function/ - part of the D3Codex reference.
