(16 . 27)(16 . 19)
384 return -1;
385 }
386
387 //input and output speeds
388 /* input and output speeds */
389 cfsetospeed(&tty, (speed_t)speed);
390 cfsetispeed(&tty, (speed_t)speed);
391
392 tty.c_cflag |= (CLOCAL | CREAD); //ignore modem controls
393 tty.c_cflag &= ~CSIZE;
394 tty.c_cflag |= CS8; //8 bit characters
395 tty.c_cflag &= ~PARENB; //no parity bit
396 tty.c_cflag &= ~CSTOPB; //only need 1 stop bit
397 tty.c_cflag &= ~CRTSCTS; //no hardware flow control
398 /* raw */
399 tty.c_lflag &= ~(ECHO | ECHOE | ECHOK);
400 tty.c_oflag &= ~OPOST;
401
402 //non-canonical mode
403 tty.c_cflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
404 tty.c_cflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
405 tty.c_cflag &= ~OPOST;
406
407 //read at least one octet at a time; timeout 1 tenth of second between octets read
408 /* read at least one octet at a time; BLOCK until at least VMIN octets read */
409 tty.c_cc[VMIN] = 1;
410 tty.c_cc[VTIME] = 1;
411 tty.c_cc[VTIME] = 0;
412
413 if (tcsetattr(fd, TCSANOW, &tty) != 0)
414 if (tcsetattr(fd, TCSAFLUSH, &tty) != 0)
415 return -1;
416
417 return 0;