Why does TIOCSTI take pointer to char instead of char?

90 Views Asked by At

When it just want 1 byte anyway, Why is it

ioctl(int fd, TIOCSTI, const char *argp)

? Wouldn't

ioctl(int fd, TIOCSTI, const char argp)

make more sense? and be faster? (it wouldn't need to follow a pointer, and the caller wouldn't need to make a valid pointer either)

Why was pointer-to-char chosen over char?

1

There are 1 best solutions below

3
user253751 On

ioctl does a lot of things, but in all cases it passes some kind of data block to, or returns a data block from, a driver that depends on the file descriptor.

The data block is completely different depending on the command. Although TIOCSTI only needs one character, there are many other ioctl commands, such as TCSETS which takes a const struct termios*. So they designed it so every ioctl command uses a pointer.

Note that on Linux, the command code itself sets the size of the data block and whether it's a get or set command. TIOCSTI evaluates to a number, and some of the bits in that number tell the ioctl function that it should send one byte of data to the driver.