Coverage Report

Created: 2025-06-22 06:28

/src/qpdf/libqpdf/QPDFSystemError.cc
Line
Count
Source (jump to first uncovered line)
1
#include <qpdf/QPDFSystemError.hh>
2
3
#include <cstring>
4
5
QPDFSystemError::QPDFSystemError(std::string const& description, int system_errno) :
6
0
    std::runtime_error(createWhat(description, system_errno)),
7
0
    description(description),
8
0
    system_errno(system_errno)
9
0
{
10
0
}
11
12
std::string
13
QPDFSystemError::createWhat(std::string const& description, int system_errno)
14
0
{
15
0
    std::string message;
16
#ifdef _MSC_VER
17
    // "94" is mentioned in the MSVC docs, but it's still safe if the
18
    // message is longer.  strerror_s is a templated function that
19
    // knows the size of buf and truncates.
20
    char buf[94];
21
    if (strerror_s(buf, system_errno) != 0) {
22
        message = description + ": failed with an unknown error";
23
    } else {
24
        message = description + ": " + buf;
25
    }
26
#else
27
0
    message = description + ": " + strerror(system_errno);
28
0
#endif
29
0
    return message;
30
0
}
31
32
std::string const&
33
QPDFSystemError::getDescription() const
34
0
{
35
0
    return this->description;
36
0
}
37
38
int
39
QPDFSystemError::getErrno() const
40
0
{
41
0
    return this->system_errno;
42
0
}