1 /*- 2 * Copyright (c) 1989 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #if defined(LIBC_SCCS) && !defined(lint) 9 static char sccsid[] = "@(#)termios.c 5.2 (Berkeley) 06/26/90"; 10 #endif /* LIBC_SCCS and not lint */ 11 12 #include <sys/types.h> 13 #include <sys/errno.h> 14 #include <sys/ioctl.h> 15 #include <sys/tty.h> 16 #include <sys/termios.h> 17 #include <stdio.h> 18 19 tcgetattr(fd, t) 20 int fd; 21 struct termios *t; 22 { 23 extern errno; 24 25 return(ioctl(fd, TIOCGETA, t)); 26 } 27 28 tcsetattr(fd, opt, t) 29 int fd, opt; 30 struct termios *t; 31 { 32 struct termios localterm; 33 34 if (opt & TCSASOFT) { 35 localterm = *t; 36 localterm.c_cflag |= CIGNORE; 37 t = &localterm; 38 opt &= TCSASOFT; 39 } 40 if (opt == TCSANOW) 41 return (ioctl(fd, TIOCSETA, t)); 42 else if (opt == TCSADRAIN) 43 return (ioctl(fd, TIOCSETAW, t)); 44 else 45 return (ioctl(fd, TIOCSETAF, t)); 46 } 47 48 tcsetpgrp(fd, pgrp) 49 { 50 return(ioctl(fd, TIOCSPGRP, &pgrp)); 51 } 52 53 tcgetpgrp(fd) 54 { 55 int pgrp; 56 57 if (ioctl(fd, TIOCGPGRP, &pgrp) < 0) 58 return(-1); 59 return(pgrp); 60 } 61 62 cfgetospeed(t) 63 struct termios *t; 64 { 65 return(t->c_ospeed); 66 } 67 68 cfgetispeed(t) 69 struct termios *t; 70 { 71 return(t->c_ispeed); 72 } 73 74 cfsetospeed(t, speed) 75 struct termios *t; 76 { 77 t->c_ospeed = speed; 78 } 79 80 cfsetispeed(t, speed) 81 struct termios *t; 82 { 83 t->c_ispeed = speed; 84 } 85 86 cfsetspeed(t, speed) 87 struct termios *t; 88 { 89 t->c_ispeed = t->c_ospeed = speed; 90 } 91 92 cfmakeraw(t) 93 struct termios *t; 94 { 95 t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|INLCR|IGNCR|ICRNL|IXON); 96 t->c_oflag &= ~(ONLCR|OXTABS); 97 t->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); 98 /* set MIN/TIME */ 99 } 100