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?
ioctldoes 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
TIOCSTIonly needs one character, there are many otherioctlcommands, such asTCSETSwhich takes aconst struct termios*. So they designed it so everyioctlcommand 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.
TIOCSTIevaluates to a number, and some of the bits in that number tell theioctlfunction that it should send one byte of data to the driver.