1 /* Copyright (C) 1993-2022 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, see
16 <https://www.gnu.org/licenses/>. */
21 #include <sys/ioctl.h>
22 #include <sys/types.h>
25 /* The difference here is that the termios structure used in the
26 kernel is not the same as we use in the libc. Therefore we must
28 #include <kernel_termios.h>
31 /* This is a gross hack around a kernel bug. If the cfsetispeed functions
32 is called with the SPEED argument set to zero this means use the same
33 speed as for output. But we don't have independent input and output
34 speeds and therefore cannot record this.
36 We use an unused bit in the `c_iflag' field to keep track of this
37 use of `cfsetispeed'. The value here must correspond to the one used
39 #define IBAUD0 020000000000
42 /* Set the state of FD to *TERMIOS_P. */
44 __tcsetattr (int fd
, int optional_actions
, const struct termios
*termios_p
)
46 struct __kernel_termios k_termios
;
47 unsigned long int cmd
;
49 switch (optional_actions
)
61 return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL
);
64 k_termios
.c_iflag
= termios_p
->c_iflag
& ~IBAUD0
;
65 k_termios
.c_oflag
= termios_p
->c_oflag
;
66 k_termios
.c_cflag
= termios_p
->c_cflag
;
67 k_termios
.c_lflag
= termios_p
->c_lflag
;
68 k_termios
.c_line
= termios_p
->c_line
;
69 #if _HAVE_C_ISPEED && _HAVE_STRUCT_TERMIOS_C_ISPEED
70 k_termios
.c_ispeed
= termios_p
->c_ispeed
;
72 #if _HAVE_C_OSPEED && _HAVE_STRUCT_TERMIOS_C_OSPEED
73 k_termios
.c_ospeed
= termios_p
->c_ospeed
;
75 memcpy (&k_termios
.c_cc
[0], &termios_p
->c_cc
[0],
76 __KERNEL_NCCS
* sizeof (cc_t
));
78 return INLINE_SYSCALL (ioctl
, 3, fd
, cmd
, &k_termios
);
80 weak_alias (__tcsetattr
, tcsetattr
)
81 libc_hidden_def (tcsetattr
)