2018-08-13 23:48:02 +00:00
|
|
|
#include <qpdf/QPDFSystemError.hh>
|
2022-02-04 21:31:31 +00:00
|
|
|
|
2023-05-20 11:22:32 +00:00
|
|
|
#include <cstring>
|
2018-08-13 23:48:02 +00:00
|
|
|
|
|
|
|
QPDFSystemError::QPDFSystemError(std::string const& description, int system_errno) :
|
|
|
|
std::runtime_error(createWhat(description, system_errno)),
|
|
|
|
description(description),
|
|
|
|
system_errno(system_errno)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
QPDFSystemError::createWhat(std::string const& description, int system_errno)
|
|
|
|
{
|
|
|
|
std::string message;
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
// "94" is mentioned in the MSVC docs, but it's still safe if the
|
|
|
|
// message is longer. strerror_s is a templated function that
|
|
|
|
// knows the size of buf and truncates.
|
|
|
|
char buf[94];
|
2018-08-14 15:39:07 +00:00
|
|
|
if (strerror_s(buf, system_errno) != 0) {
|
2018-08-13 23:48:02 +00:00
|
|
|
message = description + ": failed with an unknown error";
|
|
|
|
} else {
|
|
|
|
message = description + ": " + buf;
|
|
|
|
}
|
|
|
|
#else
|
2018-08-14 15:39:07 +00:00
|
|
|
message = description + ": " + strerror(system_errno);
|
2018-08-13 23:48:02 +00:00
|
|
|
#endif
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string const&
|
|
|
|
QPDFSystemError::getDescription() const
|
|
|
|
{
|
|
|
|
return this->description;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
QPDFSystemError::getErrno() const
|
|
|
|
{
|
|
|
|
return this->system_errno;
|
|
|
|
}
|