1 /* Copyright (C) 1991, 1993, 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. */
26 const speed_t __bsd_speeds
[] =
47 /* Set the state of FD to *TERMIOS_P. */
49 tcsetattr (fd
, optional_actions
, termios_p
)
52 const struct termios
*termios_p
;
56 struct ltchars ltchars
;
63 if (__ioctl (fd
, TIOCGETP
, &buf
) < 0 ||
64 __ioctl (fd
, TIOCGETC
, &tchars
) < 0 ||
65 __ioctl (fd
, TIOCGLTC
, <chars
) < 0 ||
67 __ioctl (fd
, TIOCGETX
, &extra
) < 0 ||
69 __ioctl (fd
, TIOCLGET
, &local
) < 0)
72 if (termios_p
== NULL
)
77 switch (optional_actions
)
86 if (tcflush (fd
, TCIFLUSH
) < 0)
94 buf
.sg_ispeed
= buf
.sg_ospeed
= -1;
95 for (i
= 0; i
<= sizeof (__bsd_speeds
) / sizeof (__bsd_speeds
[0]); ++i
)
97 if (__bsd_speeds
[i
] == termios_p
->__ispeed
)
99 if (__bsd_speeds
[i
] == termios_p
->__ospeed
)
102 if (buf
.sg_ispeed
== -1 || buf
.sg_ospeed
== -1)
104 __set_errno (EINVAL
);
108 buf
.sg_flags
&= ~(CBREAK
|RAW
);
109 if (!(termios_p
->c_lflag
& ICANON
))
110 buf
.sg_flags
|= (termios_p
->c_cflag
& ISIG
) ? CBREAK
: RAW
;
112 if (termios_p
->c_oflag
& CS8
)
117 if (termios_p
->c_lflag
& _NOFLSH
)
121 if (termios_p
->c_oflag
& OPOST
)
126 if (termios_p
->c_lflag
& ISIG
)
130 if (termios_p
->c_cflag
& CSTOPB
)
135 if (termios_p
->c_iflag
& ICRNL
)
136 buf
.sg_flags
|= CRMOD
;
138 buf
.sg_flags
&= ~CRMOD
;
139 if (termios_p
->c_iflag
& IXOFF
)
140 buf
.sg_flags
|= TANDEM
;
142 buf
.sg_flags
&= ~TANDEM
;
144 buf
.sg_flags
&= ~(ODDP
|EVENP
);
145 if (!(termios_p
->c_cflag
& PARENB
))
146 buf
.sg_flags
|= ODDP
| EVENP
;
147 else if (termios_p
->c_cflag
& PARODD
)
148 buf
.sg_flags
|= ODDP
;
150 buf
.sg_flags
|= EVENP
;
152 if (termios_p
->c_lflag
& _ECHO
)
153 buf
.sg_flags
|= ECHO
;
155 buf
.sg_flags
&= ~ECHO
;
156 if (termios_p
->c_lflag
& ECHOE
)
160 if (termios_p
->c_lflag
& ECHOK
)
164 if (termios_p
->c_lflag
& _TOSTOP
)
169 buf
.sg_erase
= termios_p
->c_cc
[VERASE
];
170 buf
.sg_kill
= termios_p
->c_cc
[VKILL
];
171 tchars
.t_eofc
= termios_p
->c_cc
[VEOF
];
172 tchars
.t_intrc
= termios_p
->c_cc
[VINTR
];
173 tchars
.t_quitc
= termios_p
->c_cc
[VQUIT
];
174 ltchars
.t_suspc
= termios_p
->c_cc
[VSUSP
];
175 tchars
.t_startc
= termios_p
->c_cc
[VSTART
];
176 tchars
.t_stopc
= termios_p
->c_cc
[VSTOP
];
178 if (__ioctl (fd
, TIOCSETP
, &buf
) < 0 ||
179 __ioctl (fd
, TIOCSETC
, &tchars
) < 0 ||
180 __ioctl (fd
, TIOCSLTC
, <chars
) < 0 ||
182 __ioctl (fd
, TIOCSETX
, &extra
) < 0 ||
184 __ioctl (fd
, TIOCLSET
, &local
) < 0)