aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/include/uhdlib/utils/isatty.hpp
blob: 1ae2c8de484db56e98a89243b75565b0d09b826b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// Copyright 2019 Ettus Research, a National Instruments Brand
//
// SPDX-License-Identifier: GPL-3.0-or-later
//

#ifndef INCLUDED_UHDLIB_UTILS_ISATTY_HPP
#define INCLUDED_UHDLIB_UTILS_ISATTY_HPP

#include <uhd/config.hpp>

namespace uhd {

#ifdef UHD_PLATFORM_WIN32

#   include <io.h>

    /*! Portable version of isatty()
     *
     * We call it is_a_tty() to distinguish from the from the POSIX version.
     * Also, we simply return a Boolean since the Windows version doesn't set
     * errno.
     */
    bool is_a_tty(const int fd)
    {
        return _isatty(fd);
    }

#elif _POSIX_C_SOURCE >= _200112L

#    include <unistd.h>

    /*! Portable version of isatty()
     *
     * We call it is_a_tty() to distinguish from the from the POSIX version.
     * Also, we simply return a Boolean since the Windows version doesn't set
     * errno.
     */
    bool is_a_tty(const int fd)
    {
        return isatty(fd);
    }

#else

    bool is_a_tty(const int fd)
    {
        return false;
    }

#endif

} /* namespace uhd */

#endif /* INCLUDED_UHDLIB_UTILS_ISATTY_HPP */