1 /* Copyright (C) 1991, 1993 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. */
27 CONST speed_t __bsd_speeds
[] =
48 /* Set the state of FD to *TERMIOS_P. */
50 DEFUN(tcsetattr
, (fd
, optional_actions
, termios_p
),
51 int fd AND
int optional_actions AND CONST
struct termios
*termios_p
)
55 struct ltchars ltchars
;
62 if (__ioctl(fd
, TIOCGETP
, &buf
) < 0 ||
63 __ioctl(fd
, TIOCGETC
, &tchars
) < 0 ||
64 __ioctl(fd
, TIOCGLTC
, <chars
) < 0 ||
66 __ioctl(fd
, TIOCGETX
, &extra
) < 0 ||
68 __ioctl(fd
, TIOCLGET
, &local
) < 0)
71 if (termios_p
== NULL
)
76 switch (optional_actions
)
85 if (tcflush(fd
, TCIFLUSH
) < 0)
93 buf
.sg_ispeed
= buf
.sg_ospeed
= -1;
94 for (i
= 0; i
<= sizeof (__bsd_speeds
) / sizeof (__bsd_speeds
[0]); ++i
)
96 if (__bsd_speeds
[i
] == termios_p
->__ispeed
)
98 if (__bsd_speeds
[i
] == termios_p
->__ospeed
)
101 if (buf
.sg_ispeed
== -1 || buf
.sg_ospeed
== -1)
107 buf
.sg_flags
&= ~(CBREAK
|RAW
);
108 if (!(termios_p
->c_lflag
& ICANON
))
109 buf
.sg_flags
|= (termios_p
->c_cflag
& ISIG
) ? CBREAK
: RAW
;
111 if (termios_p
->c_oflag
& CS8
)
116 if (termios_p
->c_lflag
& _NOFLSH
)
120 if (termios_p
->c_oflag
& OPOST
)
125 if (termios_p
->c_lflag
& ISIG
)
129 if (termios_p
->c_cflag
& CSTOPB
)
134 if (termios_p
->c_iflag
& ICRNL
)
135 buf
.sg_flags
|= CRMOD
;
137 buf
.sg_flags
&= ~CRMOD
;
138 if (termios_p
->c_iflag
& IXOFF
)
139 buf
.sg_flags
|= TANDEM
;
141 buf
.sg_flags
&= ~TANDEM
;
143 buf
.sg_flags
&= ~(ODDP
|EVENP
);
144 if (!(termios_p
->c_cflag
& PARENB
))
145 buf
.sg_flags
|= ODDP
| EVENP
;
146 else if (termios_p
->c_cflag
& PARODD
)
147 buf
.sg_flags
|= ODDP
;
149 buf
.sg_flags
|= EVENP
;
151 if (termios_p
->c_lflag
& _ECHO
)
152 buf
.sg_flags
|= ECHO
;
154 buf
.sg_flags
&= ~ECHO
;
155 if (termios_p
->c_lflag
& ECHOE
)
159 if (termios_p
->c_lflag
& ECHOK
)
163 if (termios_p
->c_lflag
& _TOSTOP
)
168 buf
.sg_erase
= termios_p
->c_cc
[VERASE
];
169 buf
.sg_kill
= termios_p
->c_cc
[VKILL
];
170 tchars
.t_eofc
= termios_p
->c_cc
[VEOF
];
171 tchars
.t_intrc
= termios_p
->c_cc
[VINTR
];
172 tchars
.t_quitc
= termios_p
->c_cc
[VQUIT
];
173 ltchars
.t_suspc
= termios_p
->c_cc
[VSUSP
];
174 tchars
.t_startc
= termios_p
->c_cc
[VSTART
];
175 tchars
.t_stopc
= termios_p
->c_cc
[VSTOP
];
177 if (__ioctl(fd
, TIOCSETP
, &buf
) < 0 ||
178 __ioctl(fd
, TIOCSETC
, &tchars
) < 0 ||
179 __ioctl(fd
, TIOCSLTC
, <chars
) < 0 ||
181 __ioctl(fd
, TIOCSETX
, &extra
) < 0 ||
183 __ioctl(fd
, TIOCLSET
, &local
) < 0)