From 15b10f9e8e2e98be8717a347304202c7aa171125 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Mon, 30 Sep 2019 13:18:19 +0200 Subject: lib: utils: Add is_a_tty() This is a portable version of POSIX's isatty(). Windows has its own version, called _isatty(). UHD thus gains its own, portable version. The underscores aren't beautiful, but they're necessary so we can distinguish the POSIX version from the UHD version. --- host/lib/include/uhdlib/utils/isatty.hpp | 55 ++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 host/lib/include/uhdlib/utils/isatty.hpp (limited to 'host/lib/include/uhdlib') diff --git a/host/lib/include/uhdlib/utils/isatty.hpp b/host/lib/include/uhdlib/utils/isatty.hpp new file mode 100644 index 000000000..1ae2c8de4 --- /dev/null +++ b/host/lib/include/uhdlib/utils/isatty.hpp @@ -0,0 +1,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 + +namespace uhd { + +#ifdef UHD_PLATFORM_WIN32 + +# include + + /*! 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 + + /*! 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 */ -- cgit v1.2.3