mirror of
https://github.com/saymrwulf/uhd.git
synced 2026-05-16 21:10:10 +00:00
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.
32 lines
904 B
C++
32 lines
904 B
C++
//
|
|
// Copyright 2019 Ettus Research, a National Instruments Brand
|
|
//
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
//
|
|
|
|
#include <uhdlib/utils/isatty.hpp>
|
|
#include <boost/test/unit_test.hpp>
|
|
#include <iostream>
|
|
#include <stdio.h>
|
|
|
|
BOOST_AUTO_TEST_CASE(test_isatty)
|
|
{
|
|
// We can't really pass or fail based on the result, because it depends on
|
|
// how the tests are executed. We'll just run it and see it doesn't crash.
|
|
if (uhd::is_a_tty(2)) {
|
|
std::cout << "stderr is a TTY" << std::endl;
|
|
} else {
|
|
std::cout << "stderr is not a TTY" << std::endl;
|
|
}
|
|
|
|
FILE* tmp_file = std::tmpfile();
|
|
#ifdef UHD_PLATFORM_WIN32
|
|
BOOST_REQUIRE(!uhd::is_a_tty(_fileno(tmp_file)));
|
|
#elif _POSIX_C_SOURCE >= _200112L
|
|
BOOST_REQUIRE(!uhd::is_a_tty(fileno(tmp_file)));
|
|
#else
|
|
// I got 99 problems but dealing with portability ain't one
|
|
BOOST_REQUIRE(!uhd::is_a_tty(99));
|
|
#endif
|
|
}
|
|
|