1 //===-- Linux implementation of tcsetattr ---------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "src/termios/tcsetattr.h"
10 #include "kernel_termios.h"
12 #include "src/__support/OSUtil/syscall.h"
13 #include "src/__support/common.h"
14 #include "src/__support/macros/config.h"
15 #include "src/errno/libc_errno.h"
17 #include <asm/ioctls.h> // Safe to include without the risk of name pollution.
18 #include <sys/syscall.h> // For syscall numbers
21 namespace LIBC_NAMESPACE_DECL
{
23 LLVM_LIBC_FUNCTION(int, tcsetattr
,
24 (int fd
, int actions
, const struct termios
*t
)) {
25 struct kernel_termios kt
;
43 kt
.c_iflag
= t
->c_iflag
;
44 kt
.c_oflag
= t
->c_oflag
;
45 kt
.c_cflag
= t
->c_cflag
;
46 kt
.c_lflag
= t
->c_lflag
;
47 size_t nccs
= KERNEL_NCCS
<= NCCS
? KERNEL_NCCS
: NCCS
;
48 for (size_t i
= 0; i
< nccs
; ++i
)
49 kt
.c_cc
[i
] = t
->c_cc
[i
];
50 if (nccs
< KERNEL_NCCS
) {
51 for (size_t i
= nccs
; i
< KERNEL_NCCS
; ++i
)
55 int ret
= LIBC_NAMESPACE::syscall_impl
<int>(SYS_ioctl
, fd
, cmd
, &kt
);
63 } // namespace LIBC_NAMESPACE_DECL