xref: /csrg-svn/lib/libc/gen/termios.c (revision 46248)
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.3 (Berkeley) 02/03/91";
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 /*
93  * Make a pre-existing termios structure into "raw" mode:
94  * character-at-a-time mode with no characters interpreted,
95  * 8-bit data path.
96  */
97 cfmakeraw(t)
98 	struct termios *t;
99 {
100 	t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
101 	t->c_oflag &= ~OPOST;
102 	t->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
103 	t->c_cflag &= ~(CSIZE|PARENB);
104 	t->c_cflag |= CS8;
105 	/* set MIN/TIME */
106 }
107