1 //===-- Linux implementation of isatty ------------------------------------===//
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/unistd/isatty.h"
11 #include "src/__support/OSUtil/syscall.h" // For internal syscall function.
12 #include "src/__support/common.h"
14 #include "src/errno/libc_errno.h"
15 #include <sys/ioctl.h> // For ioctl numbers.
16 #include <sys/syscall.h> // For syscall numbers.
18 namespace __llvm_libc
{
20 LLVM_LIBC_FUNCTION(int, isatty
, (int fd
)) {
21 constexpr int INIT_VAL
= 0x1234abcd;
22 int line_d_val
= INIT_VAL
;
23 // This gets the line dicipline of the terminal. When called on something that
24 // isn't a terminal it doesn't change line_d_val and returns -1.
25 int result
= __llvm_libc::syscall_impl(SYS_ioctl
, fd
, TIOCGETD
, &line_d_val
);
33 } // namespace __llvm_libc