Commit | Line | Data |
---|---|---|
f1fd7d4e MK |
1 | /* |
2 | * Copyright (c) 1989 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
6 | * provided that the above copyright notice and this paragraph are | |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
16 | */ | |
17 | ||
18 | #if defined(LIBC_SCCS) && !defined(lint) | |
19 | static char sccsid[] = "@(#)termios.c 5.1 (Berkeley) %G%"; | |
20 | #endif /* LIBC_SCCS and not lint */ | |
21 | ||
816ee792 MT |
22 | #include <sys/types.h> |
23 | #include <sys/errno.h> | |
24 | #include <sys/termios.h> | |
25 | #include <sys/tty.h> | |
26 | #include <stdio.h> | |
27 | ||
28 | tcgetattr(fd, t) | |
29 | int fd; | |
30 | struct termios *t; | |
31 | { | |
32 | extern errno; | |
33 | ||
34 | return(ioctl(fd, TIOCGETA, t)); | |
35 | } | |
36 | ||
37 | tcsetattr(fd, opt, t) | |
38 | int fd, opt; | |
39 | struct termios *t; | |
40 | { | |
41 | long code; | |
42 | int ret; | |
43 | extern errno; | |
44 | ||
45 | switch (opt) { | |
46 | case TCSANOW: | |
47 | code = TIOCSETA; | |
48 | break; | |
49 | case TCSADRAIN: | |
50 | code = TIOCSETAW; | |
51 | break; | |
52 | case TCSADFLUSH: | |
53 | code = TIOCSETAF; | |
54 | break; | |
55 | case TCSANOW | TCSASOFT: | |
56 | code = TIOCSETAS; | |
57 | break; | |
58 | case TCSADRAIN | TCSASOFT: | |
59 | code = TIOCSETAWS; | |
60 | break; | |
61 | case TCSADFLUSH | TCSASOFT: | |
62 | code = TIOCSETAFS; | |
63 | break; | |
64 | default: | |
65 | errno = EINVAL; | |
66 | return(-1); | |
67 | } | |
68 | return(ioctl(fd, code, t)); | |
69 | } | |
70 | ||
71 | tcsetpgrp(fd, pgrp) | |
72 | { | |
73 | return(ioctl(fd, TIOCSPGRP, &pgrp)); | |
74 | } | |
75 | ||
76 | tcgetpgrp(fd) | |
77 | { | |
78 | int pgrp; | |
79 | ||
80 | if (ioctl(fd, TIOCGPGRP, &pgrp) < 0) | |
81 | return(-1); | |
82 | return(pgrp); | |
83 | } | |
84 | ||
85 | cfgetospeed(t) | |
86 | struct termios *t; | |
87 | { | |
88 | return(t->c_ospeed); | |
89 | } | |
90 | ||
91 | cfgetispeed(t) | |
92 | struct termios *t; | |
93 | { | |
94 | return(t->c_ispeed); | |
95 | } | |
96 | ||
97 | cfsetospeed(t, speed) | |
98 | struct termios *t; | |
99 | { | |
100 | t->c_ospeed = speed; | |
101 | } | |
102 | ||
103 | cfsetispeed(t, speed) | |
104 | struct termios *t; | |
105 | { | |
106 | t->c_ispeed = speed; | |
107 | } | |
108 | ||
109 | cfsetspeed(t, speed) | |
110 | struct termios *t; | |
111 | { | |
112 | t->c_ispeed = t->c_ospeed = speed; | |
113 | } | |
114 | ||
115 | cfmakeraw(t) | |
116 | struct termios *t; | |
117 | { | |
9de4492f | 118 | t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|INLCR|IGNCR|ICRNL|IXON); |
816ee792 | 119 | t->c_oflag &= ~(ONLCR|OXTABS); |
9de4492f | 120 | t->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); |
816ee792 MT |
121 | /* set MIN/TIME */ |
122 | } |