1 /* Copyright (C) 1992, 1993, 1996, 1997, 1998 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
20 About the only thing remaining here fromthe original Linux-8086 C library
21 version by Robert de Bath <robert@mayday.compulink.co.uk>, is the general
22 layout. All else has been recently stolen from GNU libc, since that was
26 #define tcgetattr __tcgetattr
30 #include <sys/ioctl.h>
31 #include <sys/types.h>
36 /* Return 1 if FD is a terminal, 0 if not. */
38 int attribute_hidden __isatty(int fd)
41 return (tcgetattr (fd, &term) == 0);
43 strong_alias(__isatty,isatty)
47 /* Wait for pending output to be written on FD. */
48 int __libc_tcdrain (int fd)
50 /* With an argument of 1, TCSBRK waits for the output to drain. */
51 return __ioctl(fd, TCSBRK, 1);
53 weak_alias(__libc_tcdrain, tcdrain)
57 /* Suspend or restart transmission on FD. */
58 int tcflow ( int fd, int action)
60 return __ioctl(fd, TCXONC, action);
65 /* Flush pending data on FD. */
66 int tcflush ( int fd, int queue_selector)
68 return __ioctl(fd, TCFLSH, queue_selector);
73 /* Send zero bits on FD. */
74 int tcsendbreak( int fd, int duration)
76 /* The break lasts 0.25 to 0.5 seconds if DURATION is zero,
77 and an implementation-defined period if DURATION is nonzero.
78 We define a positive DURATION to be number of milliseconds to break. */
80 return __ioctl(fd, TCSBRK, 0);
83 /* Probably Linux-specific: a positive third TCSBRKP ioctl argument is
84 defined to be the number of 100ms units to break. */
85 return __ioctl(fd, TCSBRKP, (duration + 99) / 100);
87 /* ioctl can't send a break of any other duration for us.
88 This could be changed to use trickery (e.g. lower speed and
89 send a '\0') to send the break, but for now just return an error. */
97 /* Set the foreground process group ID of FD set PGRP_ID. */
98 int tcsetpgrp ( int fd, pid_t pgrp_id)
100 return __ioctl (fd, TIOCSPGRP, &pgrp_id);
105 /* Return the foreground process group ID of FD. */
106 pid_t attribute_hidden __tcgetpgrp ( int fd)
110 if (__ioctl (fd, TIOCGPGRP, &pgrp) < 0)
114 strong_alias(__tcgetpgrp,tcgetpgrp)
117 /* This is a gross hack around a kernel bug. If the cfsetispeed functions is
118 * called with the SPEED argument set to zero this means use the same speed as
119 * for output. But we don't have independent input and output speeds and
120 * therefore cannot record this.
122 * We use an unused bit in the `c_iflag' field to keep track of this use of
123 * `cfsetispeed'. The value here must correspond to the one used in
125 #define IBAUD0 020000000000
128 /* Return the output baud rate stored in *TERMIOS_P. */
129 speed_t cfgetospeed ( const struct termios *termios_p)
131 return termios_p->c_cflag & (CBAUD | CBAUDEX);
137 /* Return the input baud rate stored in *TERMIOS_P.
138 * Although for Linux there is no difference between input and output
139 * speed, the numerical 0 is a special case for the input baud rate. It
140 * should set the input baud rate to the output baud rate. */
141 speed_t cfgetispeed (const struct termios *termios_p)
143 return ((termios_p->c_iflag & IBAUD0)
144 ? 0 : termios_p->c_cflag & (CBAUD | CBAUDEX));
149 /* Set the output baud rate stored in *TERMIOS_P to SPEED. */
150 int attribute_hidden __cfsetospeed (struct termios *termios_p, speed_t speed)
152 if ((speed & ~CBAUD) != 0
153 && (speed < B57600 || speed > B460800))
159 termios_p->c_cflag &= ~(CBAUD | CBAUDEX);
160 termios_p->c_cflag |= speed;
164 strong_alias(__cfsetospeed,cfsetospeed)
168 /* Set the input baud rate stored in *TERMIOS_P to SPEED.
169 * Although for Linux there is no difference between input and output
170 * speed, the numerical 0 is a special case for the input baud rate. It
171 * should set the input baud rate to the output baud rate. */
172 int attribute_hidden __cfsetispeed ( struct termios *termios_p, speed_t speed)
174 if ((speed & ~CBAUD) != 0
175 && (speed < B57600 || speed > B460800))
182 termios_p->c_iflag |= IBAUD0;
185 termios_p->c_iflag &= ~IBAUD0;
186 termios_p->c_cflag &= ~(CBAUD | CBAUDEX);
187 termios_p->c_cflag |= speed;
192 strong_alias(__cfsetispeed,cfsetispeed)
197 extern int __cfsetospeed (struct termios *__termios_p, speed_t __speed) __THROW attribute_hidden;
198 extern int __cfsetispeed (struct termios *__termios_p, speed_t __speed) __THROW attribute_hidden;
206 static const struct speed_struct speeds[] =
283 /* Set both the input and output baud rates stored in *TERMIOS_P to SPEED. */
284 int cfsetspeed (struct termios *termios_p, speed_t speed)
288 for (cnt = 0; cnt < sizeof (speeds) / sizeof (speeds[0]); ++cnt)
289 if (speed == speeds[cnt].internal)
291 __cfsetispeed (termios_p, speed);
292 __cfsetospeed (termios_p, speed);
295 else if (speed == speeds[cnt].value)
297 __cfsetispeed (termios_p, speeds[cnt].internal);
298 __cfsetospeed (termios_p, speeds[cnt].internal);
302 __set_errno (EINVAL);
309 /* Copyright (C) 1992, 1996, 1997 Free Software Foundation, Inc.
310 This file is part of the GNU C Library.
314 /* Set *T to indicate raw mode. */
316 cfmakeraw (struct termios *t)
318 t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
319 t->c_oflag &= ~OPOST;
320 t->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
321 t->c_cflag &= ~(CSIZE|PARENB);
323 t->c_cc[VMIN] = 1; /* read returns when one char is available. */