1 /* Copyright (C) 1991, 1992, 1995, 1996, 1997 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 Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the 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 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 extern const speed_t __bsd_speeds
[]; /* Defined in tcsetattr.c. */
27 /* Put the state of FD into *TERMIOS_P. */
29 __tcgetattr (fd
, termios_p
)
31 struct termios
*termios_p
;
35 struct ltchars ltchars
;
41 if (termios_p
== NULL
)
47 if (__ioctl(fd
, TIOCGETP
, &buf
) < 0 ||
48 __ioctl(fd
, TIOCGETC
, &tchars
) < 0 ||
49 __ioctl(fd
, TIOCGLTC
, <chars
) < 0 ||
51 __ioctl(fd
, TIOCGETX
, &extra
) < 0 ||
53 __ioctl(fd
, TIOCLGET
, &local
) < 0)
56 termios_p
->__ispeed
= __bsd_speeds
[(unsigned char) buf
.sg_ispeed
];
57 termios_p
->__ospeed
= __bsd_speeds
[(unsigned char) buf
.sg_ospeed
];
59 termios_p
->c_iflag
= 0;
60 termios_p
->c_oflag
= 0;
61 termios_p
->c_cflag
= 0;
62 termios_p
->c_lflag
= 0;
63 termios_p
->c_oflag
|= CREAD
| HUPCL
;
66 termios_p
->c_oflag
|= CS8
;
69 termios_p
->c_oflag
|= CS7
;
70 if (!(buf
.sg_flags
& RAW
))
72 termios_p
->c_iflag
|= IXON
;
73 termios_p
->c_cflag
|= OPOST
;
75 termios_p
->c_lflag
|= ISIG
;
78 if ((buf
.sg_flags
& (CBREAK
|RAW
)) == 0)
79 termios_p
->c_lflag
|= ICANON
;
80 if (!(buf
.sg_flags
& RAW
) && !(local
& LLITOUT
))
81 termios_p
->c_oflag
|= OPOST
;
82 if (buf
.sg_flags
& CRMOD
)
83 termios_p
->c_iflag
|= ICRNL
;
84 if (buf
.sg_flags
& TANDEM
)
85 termios_p
->c_iflag
|= IXOFF
;
87 if (!(extra
& NOISIG
))
88 termios_p
->c_lflag
|= ISIG
;
90 termios_p
->c_cflag
|= CSTOPB
;
93 switch (buf
.sg_flags
& (EVENP
|ODDP
))
98 termios_p
->c_cflag
|= PARODD
;
100 termios_p
->c_cflag
|= PARENB
;
101 termios_p
->c_iflag
|= IGNPAR
| INPCK
;
104 if (buf
.sg_flags
& ECHO
)
105 termios_p
->c_lflag
|= _ECHO
;
107 termios_p
->c_lflag
|= ECHOE
;
109 termios_p
->c_lflag
|= ECHOK
;
111 termios_p
->c_lflag
|= _TOSTOP
;
113 termios_p
->c_lflag
|= _NOFLSH
;
115 termios_p
->c_cc
[VEOF
] = tchars
.t_eofc
;
116 termios_p
->c_cc
[VEOL
] = '\n';
117 termios_p
->c_cc
[VERASE
] = buf
.sg_erase
;
118 termios_p
->c_cc
[VKILL
] = buf
.sg_kill
;
119 termios_p
->c_cc
[VINTR
] = tchars
.t_intrc
;
120 termios_p
->c_cc
[VQUIT
] = tchars
.t_quitc
;
121 termios_p
->c_cc
[VSTART
] = tchars
.t_startc
;
122 termios_p
->c_cc
[VSTOP
] = tchars
.t_stopc
;
123 termios_p
->c_cc
[VSUSP
] = ltchars
.t_suspc
;
124 termios_p
->c_cc
[VMIN
] = -1;
125 termios_p
->c_cc
[VTIME
] = -1;
130 weak_alias (__tcgetattr
, tcgetattr
)