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