1 /* Copyright (C) 1992 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
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
22 #include <sysv_termio.h>
25 /* Put the state of FD into *TERMIOS_P. */
27 DEFUN(__tcgetattr, (fd, termios_p),
28 int fd AND struct termios *termios_p)
30 struct __sysv_termio buf;
33 if (termios_p == NULL)
39 if (__ioctl (fd, _TCGETA, &buf) < 0)
42 termio_speed = buf.c_cflag & _SYSV_CBAUD;
44 (termio_speed == _SYSV_B0 ? 0 :
45 termio_speed == _SYSV_B50 ? 50 :
46 termio_speed == _SYSV_B75 ? 75 :
47 termio_speed == _SYSV_B110 ? 110 :
48 termio_speed == _SYSV_B134 ? 134 :
49 termio_speed == _SYSV_B150 ? 150 :
50 termio_speed == _SYSV_B200 ? 200 :
51 termio_speed == _SYSV_B300 ? 300 :
52 termio_speed == _SYSV_B600 ? 600 :
53 termio_speed == _SYSV_B1200 ? 1200 :
54 termio_speed == _SYSV_B1800 ? 1800 :
55 termio_speed == _SYSV_B2400 ? 2400 :
56 termio_speed == _SYSV_B4800 ? 4800 :
57 termio_speed == _SYSV_B9600 ? 9600 :
58 termio_speed == _SYSV_B19200 ? 19200 :
59 termio_speed == _SYSV_B38400 ? 38400 :
61 termios_p->__ispeed = termios_p->__ospeed;
63 termios_p->c_iflag = 0;
64 if (buf.c_iflag & _SYSV_IGNBRK)
65 termios_p->c_iflag |= IGNBRK;
66 if (buf.c_iflag & _SYSV_BRKINT)
67 termios_p->c_iflag |= BRKINT;
68 if (buf.c_iflag & _SYSV_IGNPAR)
69 termios_p->c_iflag |= IGNPAR;
70 if (buf.c_iflag & _SYSV_PARMRK)
71 termios_p->c_iflag |= PARMRK;
72 if (buf.c_iflag & _SYSV_INPCK)
73 termios_p->c_iflag |= INPCK;
74 if (buf.c_iflag & _SYSV_ISTRIP)
75 termios_p->c_iflag |= ISTRIP;
76 if (buf.c_iflag & _SYSV_INLCR)
77 termios_p->c_iflag |= INLCR;
78 if (buf.c_iflag & _SYSV_IGNCR)
79 termios_p->c_iflag |= IGNCR;
80 if (buf.c_iflag & _SYSV_ICRNL)
81 termios_p->c_iflag |= ICRNL;
82 if (buf.c_iflag & _SYSV_IXON)
83 termios_p->c_iflag |= IXON;
84 if (buf.c_iflag & _SYSV_IXOFF)
85 termios_p->c_iflag |= IXOFF;
86 if (buf.c_iflag & _SYSV_IXANY)
87 termios_p->c_iflag |= IXANY;
88 if (buf.c_iflag & _SYSV_IMAXBEL)
89 termios_p->c_iflag |= IMAXBEL;
91 termios_p->c_oflag = 0;
92 if (buf.c_oflag & OPOST)
93 termios_p->c_oflag |= OPOST;
94 if (buf.c_oflag & ONLCR)
95 termios_p->c_oflag |= ONLCR;
96 termios_p->c_cflag = 0;
97 switch (buf.c_cflag & _SYSV_CSIZE)
100 termios_p->c_cflag |= CS5;
103 termios_p->c_cflag |= CS6;
106 termios_p->c_cflag |= CS7;
109 termios_p->c_cflag |= CS8;
112 if (buf.c_cflag & _SYSV_CSTOPB)
113 termios_p->c_cflag |= CSTOPB;
114 if (buf.c_cflag & _SYSV_CREAD)
115 termios_p->c_cflag |= CREAD;
116 if (buf.c_cflag & _SYSV_PARENB)
117 termios_p->c_cflag |= PARENB;
118 if (buf.c_cflag & _SYSV_PARODD)
119 termios_p->c_cflag |= PARODD;
120 if (buf.c_cflag & _SYSV_HUPCL)
121 termios_p->c_cflag |= HUPCL;
122 if (buf.c_cflag & _SYSV_CLOCAL)
123 termios_p->c_cflag |= CLOCAL;
124 termios_p->c_lflag = 0;
125 if (buf.c_lflag & _SYSV_ISIG)
126 termios_p->c_lflag |= _ISIG;
127 if (buf.c_lflag & _SYSV_ICANON)
128 termios_p->c_lflag |= _ICANON;
129 if (buf.c_lflag & _SYSV_ECHO)
130 termios_p->c_lflag |= _ECHO;
131 if (buf.c_lflag & _SYSV_ECHOE)
132 termios_p->c_lflag |= _ECHOE;
133 if (buf.c_lflag & _SYSV_ECHOK)
134 termios_p->c_lflag |= _ECHOK;
135 if (buf.c_lflag & _SYSV_ECHONL)
136 termios_p->c_lflag |= _ECHONL;
137 if (buf.c_lflag & _SYSV_NOFLSH)
138 termios_p->c_lflag |= _NOFLSH;
139 if (buf.c_lflag & _SYSV_TOSTOP)
140 termios_p->c_lflag |= _TOSTOP;
141 if (buf.c_lflag & _SYSV_ECHOKE)
142 termios_p->c_lflag |= ECHOKE;
143 if (buf.c_lflag & _SYSV_ECHOPRT)
144 termios_p->c_lflag |= ECHOPRT;
145 if (buf.c_lflag & _SYSV_ECHOCTL)
146 termios_p->c_lflag |= ECHOCTL;
147 if (buf.c_lflag & _SYSV_FLUSHO)
148 termios_p->c_lflag |= FLUSHO;
149 if (buf.c_lflag & _SYSV_PENDIN)
150 termios_p->c_lflag |= PENDIN;
151 if (buf.c_lflag & _SYSV_IEXTEN)
152 termios_p->c_lflag |= IEXTEN;
154 termios_p->c_cc[VEOF] = buf.c_cc[_SYSV_VEOF];
155 termios_p->c_cc[VEOL] = buf.c_cc[_SYSV_VEOL];
156 termios_p->c_cc[VEOL2] = buf.c_cc[_SYSV_VEOL2];
157 termios_p->c_cc[VERASE] = buf.c_cc[_SYSV_VERASE];
158 termios_p->c_cc[VKILL] = buf.c_cc[_SYSV_VKILL];
159 termios_p->c_cc[VINTR] = buf.c_cc[_SYSV_VINTR];
160 termios_p->c_cc[VQUIT] = buf.c_cc[_SYSV_VQUIT];
161 termios_p->c_cc[VSTART] = '\021'; /* XON (^Q). */
162 termios_p->c_cc[VSTOP] = '\023'; /* XOFF (^S). */
163 termios_p->c_cc[VSUSP] = '\0'; /* System V release 3 lacks job control. */
164 termios_p->c_cc[VMIN] = -1;
165 termios_p->c_cc[VTIME] = -1;