Comment 5 for bug 72200

Revision history for this message
Jörg Höhle (joerg-cyril-hoehle) wrote : ioctl(TCSBRK,1) on socket yields EFAULT (expected EINVAL/ENOTTY)

I was told the Linux kernel hackers want code that goes straight to the bones, i.e. use ioctl() instead of the tcdrain() wrapper. Here it is.

/* tcdrain() returns EFAULT (a serious error) on sockets
 * tcdrain() is equivalent to ioctl(TCSBRK) on Linux and Solaris
 */
#include <sys/ioctl.h>
#include <termios.h> /* TCSBRK is 0x5409 */
#include <errno.h>
#include <stdio.h>

int main () {
  int i;
  for (i=0; i<=2; i++) {
    int retval, save;
    errno = 0;
    retval = ioctl(i,TCSBRK,1);
    save = errno;
    printf("ioctl(%d,TCSBRK,1)=(%d,%d)\n",i,retval,save);
    /* printf("ioctl(%d,TCSBRK,1)=(%d,%d=%s)\n",i,retval,save,
    save ? strerror(save) : ""); */
  }
  return 0;
}