]>
Commit | Line | Data |
---|---|---|
478b92f0 UD |
1 | /* Copyright (C) 1991, 1992, 1995, 1996, 1997 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. | |
3 | ||
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. | |
8 | ||
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. | |
13 | ||
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. */ | |
28f540f4 | 18 | |
28f540f4 RM |
19 | #include <errno.h> |
20 | #include <stddef.h> | |
21 | #include <termios.h> | |
22 | ||
23 | #include "bsdtty.h" | |
24 | ||
c4029823 | 25 | extern const speed_t __bsd_speeds[]; /* Defined in tcsetattr.c. */ |
28f540f4 RM |
26 | |
27 | /* Put the state of FD into *TERMIOS_P. */ | |
28 | int | |
c4029823 UD |
29 | __tcgetattr (fd, termios_p) |
30 | int fd; | |
31 | struct termios *termios_p; | |
28f540f4 RM |
32 | { |
33 | struct sgttyb buf; | |
34 | struct tchars tchars; | |
35 | struct ltchars ltchars; | |
36 | int local; | |
37 | #ifdef TIOCGETX | |
38 | int extra; | |
39 | #endif | |
40 | ||
41 | if (termios_p == NULL) | |
42 | { | |
c4029823 | 43 | __set_errno (EINVAL); |
28f540f4 RM |
44 | return -1; |
45 | } | |
46 | ||
47 | if (__ioctl(fd, TIOCGETP, &buf) < 0 || | |
48 | __ioctl(fd, TIOCGETC, &tchars) < 0 || | |
49 | __ioctl(fd, TIOCGLTC, <chars) < 0 || | |
50 | #ifdef TIOCGETX | |
51 | __ioctl(fd, TIOCGETX, &extra) < 0 || | |
52 | #endif | |
53 | __ioctl(fd, TIOCLGET, &local) < 0) | |
54 | return -1; | |
55 | ||
56 | termios_p->__ispeed = __bsd_speeds[(unsigned char) buf.sg_ispeed]; | |
57 | termios_p->__ospeed = __bsd_speeds[(unsigned char) buf.sg_ospeed]; | |
58 | ||
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; | |
64 | #ifdef LPASS8 | |
65 | if (local & LPASS8) | |
66 | termios_p->c_oflag |= CS8; | |
67 | else | |
68 | #endif | |
69 | termios_p->c_oflag |= CS7; | |
70 | if (!(buf.sg_flags & RAW)) | |
71 | { | |
72 | termios_p->c_iflag |= IXON; | |
73 | termios_p->c_cflag |= OPOST; | |
74 | #ifndef NOISIG | |
75 | termios_p->c_lflag |= ISIG; | |
76 | #endif | |
77 | } | |
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; | |
86 | #ifdef TIOCGETX | |
87 | if (!(extra & NOISIG)) | |
88 | termios_p->c_lflag |= ISIG; | |
89 | if (extra & STOPB) | |
90 | termios_p->c_cflag |= CSTOPB; | |
91 | #endif | |
92 | ||
93 | switch (buf.sg_flags & (EVENP|ODDP)) | |
94 | { | |
95 | case EVENP|ODDP: | |
96 | break; | |
97 | case ODDP: | |
98 | termios_p->c_cflag |= PARODD; | |
99 | default: | |
100 | termios_p->c_cflag |= PARENB; | |
101 | termios_p->c_iflag |= IGNPAR | INPCK; | |
102 | break; | |
103 | } | |
104 | if (buf.sg_flags & ECHO) | |
105 | termios_p->c_lflag |= _ECHO; | |
106 | if (local & LCRTERA) | |
107 | termios_p->c_lflag |= ECHOE; | |
108 | if (local & LCRTKIL) | |
109 | termios_p->c_lflag |= ECHOK; | |
110 | if (local & LTOSTOP) | |
111 | termios_p->c_lflag |= _TOSTOP; | |
112 | if (local & LNOFLSH) | |
113 | termios_p->c_lflag |= _NOFLSH; | |
114 | ||
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; | |
126 | ||
127 | return 0; | |
128 | } | |
129 | ||
130 | weak_alias (__tcgetattr, tcgetattr) |