LCOV - code coverage report
Current view: top level - snapdev - isatty.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 5 5
Test Date: 2026-02-16 17:48:13 Functions: 100.0 % 1 1
Legend: Lines: hit not hit

            Line data    Source code
       1              : // Copyright (c) 2011-2026  Made to Order Software Corp.  All Rights Reserved
       2              : //
       3              : // https://snapwebsites.org/project/snapdev
       4              : // contact@m2osw.com
       5              : //
       6              : // This program is free software: you can redistribute it and/or modify
       7              : // it under the terms of the GNU General Public License as published by
       8              : // the Free Software Foundation, either version 3 of the License, or
       9              : // (at your option) any later version.
      10              : //
      11              : // This program is distributed in the hope that it will be useful,
      12              : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      13              : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14              : // GNU General Public License for more details.
      15              : //
      16              : // You should have received a copy of the GNU General Public License
      17              : // along with this program.  If not, see <https://www.gnu.org/licenses/>.
      18              : #pragma once
      19              : 
      20              : // self
      21              : //
      22              : #include    <snapdev/stream_fd.h>
      23              : 
      24              : 
      25              : 
      26              : // C
      27              : //
      28              : #include    <unistd.h>
      29              : 
      30              : 
      31              : 
      32              : namespace snapdev
      33              : {
      34              : 
      35              : 
      36              : 
      37              : /** \brief Check whether a C++ iostream is a TTY.
      38              :  *
      39              :  * This function checks the specified stream and if it represents a TTY
      40              :  * returns true.
      41              :  *
      42              :  * If the stream is not a standard file stream, then the function always
      43              :  * returns false, even if ultimately the stream does represent a TTY. This
      44              :  * is because we can really only handle the standard fstream's objects here.
      45              :  *
      46              :  * \tparam _CharT  type of character this stream handles.
      47              :  * \tparam _Traits  traits of the characters; based on CharT by default.
      48              :  * \param[in] stream  The stream to check.
      49              :  *
      50              :  * \return true if \p stream is a TTY.
      51              :  */
      52              : template<typename _CharT
      53              :        , typename _Traits = std::char_traits<_CharT>>
      54            6 : bool isatty(std::basic_ios<_CharT, _Traits> const & stream)
      55              : {
      56            6 :     int const r(stream_fd(stream));
      57            6 :     if(r < 0)
      58              :     {
      59            1 :         return false;
      60              :     }
      61              : 
      62            5 :     return ::isatty(r);
      63              : }
      64              : 
      65              : 
      66              : 
      67              : } // namespace snapdev
      68              : // vim: ts=4 sw=4 et
      69              : 
        

Generated by: LCOV version 2.0-1

Snap C++ | List of projects | List of versions