* added compilers lcc and bcc (linux86)
[mascara-docs.git] / compilers / linux86-0.16.17 / libc / termios / termios.c
bloba617e86f4d9c8071f3908173d8786628f840b42c
1 /* Copyright (C) 1996 Robert de Bath <robert@mayday.compulink.co.uk> This
2 * file is part of the Linux-8086 C library and is distributed under the
3 * GNU Library General Public License.
4 */
6 /* Note: This is based loosely on the Glib termios routines. */
8 #ifndef __MSDOS__
10 #include <errno.h>
11 #include <stddef.h>
12 #include <sys/ioctl.h>
13 #include <termios.h>
15 #ifdef L_isatty
16 isatty(fd)
17 int fd;
19 struct termios term;
20 int rv, err = errno;
21 rv= (ioctl(fd, TCGETS, &term)==0);
22 if( rv==0 && errno == ENOSYS )
23 rv = (fd<3);
24 errno = err;
25 return rv;
27 #endif
29 #ifdef L_tcgetattr
30 int
31 tcgetattr(fd, term)
32 int fd;
33 struct termios *term;
35 return ioctl(fd, TCGETS, term);
37 #endif
39 #ifdef L_tcsetattr
40 int
41 tcsetattr(fildes, optional_actions, termios_p)
42 int fildes;
43 int optional_actions;
44 struct termios *termios_p;
46 switch (optional_actions)
48 case TCSANOW:
49 return ioctl(fildes, TCSETS, termios_p);
50 case TCSADRAIN:
51 return ioctl(fildes, TCSETSW, termios_p);
52 case TCSAFLUSH:
53 return ioctl(fildes, TCSETSF, termios_p);
54 default:
55 errno = EINVAL;
56 return -1;
59 #endif
61 #ifdef L_tcdrain
62 /* Wait for pending output to be written on FD. */
63 int
64 tcdrain(fd)
65 int fd;
67 /* With an argument of 1, TCSBRK just waits for output to drain. */
68 return ioctl(fd, TCSBRK, 1);
70 #endif
72 #ifdef L_tcflow
73 int
74 tcflow(fd, action)
75 int fd;
76 int action;
78 return ioctl(fd, TCXONC, action);
80 #endif
82 #ifdef L_tcflush
83 /* Flush pending data on FD. */
84 int
85 tcflush(fd, queue_selector)
86 int fd;
87 int queue_selector;
89 return ioctl(fd, TCFLSH, queue_selector);
91 #endif
93 #ifdef L_tcsendbreak
94 /* Send zero bits on FD. */
95 int
96 tcsendbreak(fd, duration)
97 int fd;
98 int duration;
101 * The break lasts 0.25 to 0.5 seconds if DURATION is zero, and an
102 * implementation-defined period if DURATION is nonzero. We define a
103 * positive DURATION to be number of milliseconds to break.
105 if (duration <= 0)
106 return ioctl(fd, TCSBRK, 0);
109 * ioctl can't send a break of any other duration for us. This could be
110 * changed to use trickery (e.g. lower speed and send a '\0') to send
111 * the break, but for now just return an error.
113 errno = EINVAL;
114 return -1;
116 #endif
118 #ifdef L_tcsetpgrp
119 /* Set the foreground process group ID of FD set PGRP_ID. */
121 tcsetpgrp(fd, pgrp_id)
122 int fd;
123 pid_t pgrp_id;
125 return ioctl(fd, TIOCSPGRP, &pgrp_id);
127 #endif
129 #ifdef L_tcgetpgrp
130 /* Return the foreground process group ID of FD. */
131 pid_t
132 tcgetpgrp(fd)
133 int fd;
135 int pgrp;
136 if (ioctl(fd, TIOCGPGRP, &pgrp) < 0)
137 return (pid_t) - 1;
138 return (pid_t) pgrp;
140 #endif
142 #ifdef L_cfgetospeed
143 speed_t cfgetospeed(tp)
144 struct termios *tp;
146 return (tp->c_cflag & CBAUD);
148 #endif
150 #ifdef L_cfgetispeed
151 speed_t cfgetispeed(tp)
152 struct termios *tp;
154 return (tp->c_cflag & CBAUD);
156 #endif
158 #ifdef L_cfsetospeed
159 int cfsetospeed(tp, speed)
160 struct termios *tp; speed_t speed;
162 #ifdef CBAUDEX
163 if ((speed & ~CBAUD) ||
164 ((speed & CBAUDEX) && (speed < B57600 || speed > B115200)))
165 return 0;
166 #else
167 if (speed & ~CBAUD)
168 return 0;
169 #endif
170 tp->c_cflag &= ~CBAUD;
171 tp->c_cflag |= speed;
173 return 0;
175 #endif
177 #ifdef L_cfsetispeed
178 int cfsetispeed(tp, speed)
179 struct termios *tp; speed_t speed;
181 return cfsetospeed(tp, speed);
183 #endif
185 /* From linux libc-4.6.27 again */
186 #ifdef L_cfmakeraw
187 /* Copyright (C) 1992 Free Software Foundation, Inc.
188 This file is part of the GNU C Library.*/
190 void
191 cfmakeraw(t)
192 struct termios *t;
194 /* I changed it to the current form according to the suggestions
195 * from Bruce Evans. Thanks Bruce. Please report the problems to
196 * H.J. Lu (hlu@eecs.wsu.edu).
200 * I took out the bits commented out by #if 1...#else - RHP
203 /* VMIN = 0 means non-blocking for Linux */
204 t->c_cc[VMIN] = 1; t->c_cc[VTIME] = 1;
205 /* clear some bits with &= ~(bits), set others with |= */
206 t->c_cflag &= ~(CSIZE|PARENB|CSTOPB);
207 t->c_cflag |= (CS8|HUPCL|CREAD);
208 t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|INPCK|ISTRIP);
209 t->c_iflag &= ~(INLCR|IGNCR|ICRNL|IXON|IXOFF);
210 t->c_iflag |= (BRKINT|IGNPAR);
211 t->c_oflag &= ~(OPOST|OLCUC|OCRNL|ONOCR|ONLRET|OFILL|OFDEL);
212 t->c_oflag &= ~(NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY);
213 t->c_oflag |= (ONLCR|NL0|CR0|TAB3|BS0|VT0|FF0);
214 t->c_lflag &= ~(ISIG|ICANON|IEXTEN|ECHO|ECHOE|ECHOK|ECHONL);
215 t->c_lflag &= ~(NOFLSH|XCASE);
216 t->c_lflag &= ~(ECHOPRT|ECHOCTL|ECHOKE);
218 #endif
220 #endif