1 //===-- Linux implementation of tcgetattr ---------------------------------===//
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/tcgetattr.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, tcgetattr
, (int fd
, struct termios
*t
)) {
24 LIBC_NAMESPACE::kernel_termios kt
;
25 int ret
= LIBC_NAMESPACE::syscall_impl
<int>(SYS_ioctl
, fd
, TCGETS
, &kt
);
30 t
->c_iflag
= kt
.c_iflag
;
31 t
->c_oflag
= kt
.c_oflag
;
32 t
->c_cflag
= kt
.c_cflag
;
33 t
->c_lflag
= kt
.c_lflag
;
34 t
->c_ispeed
= kt
.c_cflag
& CBAUD
;
35 t
->c_ospeed
= kt
.c_cflag
& CBAUD
;
37 size_t nccs
= KERNEL_NCCS
<= NCCS
? KERNEL_NCCS
: NCCS
;
38 for (size_t i
= 0; i
< nccs
; ++i
)
39 t
->c_cc
[i
] = kt
.c_cc
[i
];
41 for (size_t i
= nccs
; i
< NCCS
; ++i
)
47 } // namespace LIBC_NAMESPACE_DECL