1 //
2 // Copyright 2019 Ettus Research, a National Instruments Brand
3 //
4 // SPDX-License-Identifier: GPL-3.0-or-later
5 //
6 
7 #pragma once
8 
9 #include <uhd/config.hpp>
10 #include <uhdlib/utils/narrow.hpp>
11 
12 namespace uhd {
13 
14 #ifdef UHD_PLATFORM_WIN32
15 
16 #    include <io.h>
17 
18 /*! Portable version of isatty()
19  *
20  * We call it is_a_tty() to distinguish from the from the POSIX version.
21  * Also, we simply return a Boolean since the Windows version doesn't set
22  * errno.
23  */
is_a_tty(const int fd)24 bool is_a_tty(const int fd)
25 {
26     return uhd::narrow_cast<bool>(_isatty(fd));
27 }
28 
29 #elif _POSIX_C_SOURCE >= _200112L
30 
31 #    include <unistd.h>
32 
33 /*! Portable version of isatty()
34  *
35  * We call it is_a_tty() to distinguish from the from the POSIX version.
36  * Also, we simply return a Boolean since the Windows version doesn't set
37  * errno.
38  */
39 bool is_a_tty(const int fd)
40 {
41     return isatty(fd);
42 }
43 
44 #else
45 
46 bool is_a_tty(const int fd)
47 {
48     return false;
49 }
50 
51 #endif
52 
53 } /* namespace uhd */
54