Coverage Report

Created: 2025-06-13 06:46

/src/Fast-DDS/thirdparty/taocpp-pegtl/pegtl/internal/cstream_reader.hpp
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2016-2020 Dr. Colin Hirsch and Daniel Frey
2
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/
3
4
#ifndef TAO_PEGTL_INTERNAL_CSTREAM_READER_HPP
5
#define TAO_PEGTL_INTERNAL_CSTREAM_READER_HPP
6
7
#include <cassert>
8
#include <cstddef>
9
#include <cstdio>
10
11
#include "../config.hpp"
12
#include "../input_error.hpp"
13
14
namespace tao
15
{
16
   namespace TAO_PEGTL_NAMESPACE
17
   {
18
      namespace internal
19
      {
20
         struct cstream_reader
21
         {
22
            explicit cstream_reader( std::FILE* s ) noexcept
23
               : m_cstream( s )
24
0
            {
25
0
               assert( m_cstream != nullptr );
26
0
            }
27
28
            std::size_t operator()( char* buffer, const std::size_t length ) const
29
0
            {
30
0
               if( const auto r = std::fread( buffer, 1, length, m_cstream ) ) {
31
0
                  return r;
32
0
               }
33
0
               if( std::feof( m_cstream ) != 0 ) {
34
0
                  return 0;
35
0
               }
36
0
               // Please contact us if you know how to provoke the following exception.
37
0
               // The example on cppreference.com doesn't work, at least not on macOS.
38
0
               TAO_PEGTL_THROW_INPUT_ERROR( "error in fread() from cstream" );  // LCOV_EXCL_LINE
39
0
            }
40
41
            std::FILE* m_cstream;
42
         };
43
44
      }  // namespace internal
45
46
   }  // namespace TAO_PEGTL_NAMESPACE
47
48
}  // namespace tao
49
50
#endif