144301Smarc /*- 238597Skarels * Copyright (c) 1989 The Regents of the University of California. 338597Skarels * All rights reserved. 438597Skarels * 544301Smarc * %sccs.include.redist.c% 638597Skarels */ 738597Skarels 838597Skarels #if defined(LIBC_SCCS) && !defined(lint) 9*46248Skarels static char sccsid[] = "@(#)termios.c 5.3 (Berkeley) 02/03/91"; 1038597Skarels #endif /* LIBC_SCCS and not lint */ 1138597Skarels 1235766Smarc #include <sys/types.h> 1335766Smarc #include <sys/errno.h> 1444301Smarc #include <sys/ioctl.h> 1544301Smarc #include <sys/tty.h> 1635766Smarc #include <sys/termios.h> 1735766Smarc #include <stdio.h> 1835766Smarc 1935766Smarc tcgetattr(fd, t) 2035766Smarc int fd; 2135766Smarc struct termios *t; 2235766Smarc { 2335766Smarc extern errno; 2435766Smarc 2535766Smarc return(ioctl(fd, TIOCGETA, t)); 2635766Smarc } 2735766Smarc 2835766Smarc tcsetattr(fd, opt, t) 2935766Smarc int fd, opt; 3035766Smarc struct termios *t; 3135766Smarc { 3244301Smarc struct termios localterm; 3335766Smarc 3444301Smarc if (opt & TCSASOFT) { 3544301Smarc localterm = *t; 3644301Smarc localterm.c_cflag |= CIGNORE; 3744301Smarc t = &localterm; 3844301Smarc opt &= TCSASOFT; 3935766Smarc } 4044301Smarc if (opt == TCSANOW) 4144301Smarc return (ioctl(fd, TIOCSETA, t)); 4244301Smarc else if (opt == TCSADRAIN) 4344301Smarc return (ioctl(fd, TIOCSETAW, t)); 4444301Smarc else 4544301Smarc return (ioctl(fd, TIOCSETAF, t)); 4635766Smarc } 4735766Smarc 4835766Smarc tcsetpgrp(fd, pgrp) 4935766Smarc { 5035766Smarc return(ioctl(fd, TIOCSPGRP, &pgrp)); 5135766Smarc } 5235766Smarc 5335766Smarc tcgetpgrp(fd) 5435766Smarc { 5535766Smarc int pgrp; 5635766Smarc 5735766Smarc if (ioctl(fd, TIOCGPGRP, &pgrp) < 0) 5835766Smarc return(-1); 5935766Smarc return(pgrp); 6035766Smarc } 6135766Smarc 6235766Smarc cfgetospeed(t) 6335766Smarc struct termios *t; 6435766Smarc { 6535766Smarc return(t->c_ospeed); 6635766Smarc } 6735766Smarc 6835766Smarc cfgetispeed(t) 6935766Smarc struct termios *t; 7035766Smarc { 7135766Smarc return(t->c_ispeed); 7235766Smarc } 7335766Smarc 7435766Smarc cfsetospeed(t, speed) 7535766Smarc struct termios *t; 7635766Smarc { 7735766Smarc t->c_ospeed = speed; 7835766Smarc } 7935766Smarc 8035766Smarc cfsetispeed(t, speed) 8135766Smarc struct termios *t; 8235766Smarc { 8335766Smarc t->c_ispeed = speed; 8435766Smarc } 8535766Smarc 8635766Smarc cfsetspeed(t, speed) 8735766Smarc struct termios *t; 8835766Smarc { 8935766Smarc t->c_ispeed = t->c_ospeed = speed; 9035766Smarc } 9135766Smarc 92*46248Skarels /* 93*46248Skarels * Make a pre-existing termios structure into "raw" mode: 94*46248Skarels * character-at-a-time mode with no characters interpreted, 95*46248Skarels * 8-bit data path. 96*46248Skarels */ 9735766Smarc cfmakeraw(t) 9835766Smarc struct termios *t; 9935766Smarc { 100*46248Skarels t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); 101*46248Skarels t->c_oflag &= ~OPOST; 10238596Skarels t->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); 103*46248Skarels t->c_cflag &= ~(CSIZE|PARENB); 104*46248Skarels t->c_cflag |= CS8; 10535766Smarc /* set MIN/TIME */ 10635766Smarc } 107