Merge branch 'remove-strerror' into 'master'

Remove strerror usages

Closes #7151

See merge request OpenMW/openmw!2664
7220-lua-add-a-general-purpose-lexical-parser
psi29a 2 years ago
commit 92f88c16a9

@ -439,7 +439,8 @@ namespace
auto stream = Files::openBinaryInputFileStream(info.filename);
if (!stream->is_open())
{
std::cout << "Failed to open file: " << std::strerror(errno) << '\n';
std::cout << "Failed to open file " << info.filename << ": " << std::generic_category().message(errno)
<< '\n';
return -1;
}

@ -177,7 +177,7 @@ bool Wizard::UnshieldWorker::setupSettings()
if (file.fail())
{
emit error(tr("Failed to open Morrowind configuration file!"),
tr("Opening %1 failed: %2.").arg(getIniPath(), strerror(errno)));
tr("Opening %1 failed: %2.").arg(getIniPath(), std::generic_category().message(errno).c_str()));
return false;
}
@ -196,14 +196,14 @@ bool Wizard::UnshieldWorker::writeSettings()
if (file.fail())
{
emit error(tr("Failed to open Morrowind configuration file!"),
tr("Opening %1 failed: %2.").arg(getIniPath(), strerror(errno)));
tr("Opening %1 failed: %2.").arg(getIniPath(), std::generic_category().message(errno).c_str()));
return false;
}
if (!mIniSettings.writeFile(getIniPath(), file, mIniEncoding))
{
emit error(tr("Failed to write Morrowind configuration file!"),
tr("Writing to %1 failed: %2.").arg(getIniPath(), strerror(errno)));
tr("Writing to %1 failed: %2.").arg(getIniPath(), std::generic_category().message(errno).c_str()));
return false;
}

@ -176,7 +176,8 @@ static void gdb_info(pid_t pid)
/* Clean up */
if (remove(respfile) != 0)
Log(Debug::Warning) << "Warning: can not remove file '" << respfile << "': " << std::strerror(errno);
Log(Debug::Warning) << "Warning: can not remove file '" << respfile
<< "': " << std::generic_category().message(errno);
}
else
{
@ -184,9 +185,11 @@ static void gdb_info(pid_t pid)
if (fd >= 0)
{
if (close(fd) != 0)
Log(Debug::Warning) << "Warning: can not close file '" << respfile << "': " << std::strerror(errno);
Log(Debug::Warning) << "Warning: can not close file '" << respfile
<< "': " << std::generic_category().message(errno);
else if (remove(respfile) != 0)
Log(Debug::Warning) << "Warning: can not remove file '" << respfile << "': " << std::strerror(errno);
Log(Debug::Warning) << "Warning: can not remove file '" << respfile
<< "': " << std::generic_category().message(errno);
}
printf("!!! Could not create gdb command file\n");
}

@ -56,7 +56,8 @@ namespace Files
const auto err = ec.value();
if (err != 0)
{
Log(Debug::Warning) << "Error " << err << " " << std::strerror(err) << " when changing current directory";
Log(Debug::Warning) << "Error " << err << " " << std::generic_category().message(errno)
<< " when changing current directory";
}
}

@ -10,8 +10,8 @@ namespace Files
{
auto stream = std::make_unique<std::ifstream>(path, std::ios::binary);
if (!stream->is_open())
throw std::runtime_error(
"Failed to open '" + Files::pathToUnicodeString(path) + "' for reading: " + std::strerror(errno));
throw std::system_error(errno, std::generic_category(),
"Failed to open '" + Files::pathToUnicodeString(path) + "' for reading");
stream->exceptions(std::ios::badbit);
return stream;
}

@ -7,6 +7,7 @@
#include <stdexcept>
#include <string>
#include <string_view>
#include <system_error>
#include <vector>
namespace Misc::StringUtils
@ -50,12 +51,11 @@ namespace Misc::StringUtils
{
const int size = std::snprintf(nullptr, 0, fmt, argument(args)...);
if (size < 0)
throw std::runtime_error(
std::string("Failed to compute resulting string size: ") + std::strerror(errno));
throw std::system_error(errno, std::generic_category(), "Failed to compute resulting string size");
// Note: sprintf also writes a trailing null character. We should remove it.
std::string ret(static_cast<std::size_t>(size) + 1, '\0');
if (std::sprintf(ret.data(), fmt, argument(args)...) < 0)
throw std::runtime_error(std::string("Failed to format string: ") + std::strerror(errno));
throw std::system_error(errno, std::generic_category(), "Failed to format string");
ret.erase(static_cast<std::size_t>(size));
return ret;
}

@ -20,7 +20,7 @@ namespace Misc
Log(Debug::Verbose) << "Using idle priority for thread=" << std::this_thread::get_id();
else
Log(Debug::Warning) << "Failed to set idle priority for thread=" << std::this_thread::get_id() << ": "
<< std::strerror(errno);
<< std::generic_category().message(errno);
}
}
@ -56,7 +56,7 @@ namespace Misc
Log(Debug::Verbose) << "Using idle priority for thread=" << std::this_thread::get_id();
else
Log(Debug::Warning) << "Failed to set idle priority for thread=" << std::this_thread::get_id() << ": "
<< std::strerror(errno);
<< std::generic_category().message(errno);
}
}

@ -43,8 +43,8 @@ namespace Platform::File
auto handle = ::open(filename.c_str(), openFlags, 0);
if (handle == -1)
{
throw std::runtime_error(std::string("Failed to open '") + Files::pathToUnicodeString(filename)
+ "' for reading: " + strerror(errno));
throw std::system_error(errno, std::generic_category(),
std::string("Failed to open '") + Files::pathToUnicodeString(filename) + "' for reading");
}
return static_cast<Handle>(handle);
}
@ -63,7 +63,7 @@ namespace Platform::File
if (::lseek(nativeHandle, position, nativeSeekType) == -1)
{
throw std::runtime_error("An lseek() call failed: " + std::string(strerror(errno)));
throw std::system_error(errno, std::generic_category(), "An lseek() call failed");
}
}
@ -85,7 +85,7 @@ namespace Platform::File
size_t position = ::lseek(nativeHandle, 0, SEEK_CUR);
if (position == size_t(-1))
{
throw std::runtime_error("An lseek() call failed: " + std::string(strerror(errno)));
throw std::system_error(errno, std::generic_category(), "An lseek() call failed");
}
return position;
}
@ -97,8 +97,8 @@ namespace Platform::File
int amount = ::read(nativeHandle, data, size);
if (amount == -1)
{
throw std::runtime_error(
"An attempt to read " + std::to_string(size) + " bytes failed: " + strerror(errno));
throw std::system_error(
errno, std::generic_category(), "An attempt to read " + std::to_string(size) + " bytes failed");
}
return amount;
}

@ -34,8 +34,8 @@ namespace Platform::File
FILE* handle = fopen(filename.c_str(), "rb");
if (handle == nullptr)
{
throw std::runtime_error(std::string("Failed to open '") + Files::pathToUnicodeString(filename)
+ "' for reading: " + strerror(errno));
throw std::system_error(errno, std::generic_category(),
std::string("Failed to open '") + Files::pathToUnicodeString(filename) + "' for reading");
}
return static_cast<Handle>(reinterpret_cast<intptr_t>(handle));
}
@ -52,7 +52,7 @@ namespace Platform::File
const auto nativeSeekType = getNativeSeekType(type);
if (fseek(nativeHandle, position, nativeSeekType) != 0)
{
throw std::runtime_error(std::string("An fseek() call failed: ") + strerror(errno));
throw std::system_error(errno, std::generic_category(), std::string("An fseek() call failed"));
}
}
@ -75,7 +75,7 @@ namespace Platform::File
long position = ftell(nativeHandle);
if (position == -1)
{
throw std::runtime_error(std::string("An ftell() call failed: ") + strerror(errno));
throw std::system_error(errno, std::generic_category(), std::string("An ftell() call failed"));
}
return static_cast<size_t>(position);
}
@ -87,8 +87,8 @@ namespace Platform::File
int amount = fread(data, 1, size, nativeHandle);
if (amount == 0 && ferror(nativeHandle))
{
throw std::runtime_error(
std::string("An attempt to read ") + std::to_string(size) + " bytes failed: " + strerror(errno));
throw std::system_error(errno, std::generic_category(),
std::string("An attempt to read ") + std::to_string(size) + " bytes failed");
}
return static_cast<size_t>(amount);
}

Loading…
Cancel
Save