mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Introduce proper error handling for file streams
This commit is contained in:
parent
c38e0d05bf
commit
39fd9b93c3
23 changed files with 235 additions and 149 deletions
|
@ -582,7 +582,7 @@ static void createCacheDirTag()
|
|||
if (fs::PathExists(path))
|
||||
return;
|
||||
fs::CreateAllDirs(path_cache);
|
||||
std::ofstream ofs(path, std::ios::out | std::ios::binary);
|
||||
auto ofs = open_ofstream(path.c_str(), false);
|
||||
if (!ofs.good())
|
||||
return;
|
||||
ofs << "Signature: 8a477f597d28d172789f06886806bc55\n"
|
||||
|
@ -800,6 +800,21 @@ std::string QuoteArgv(const std::string &arg)
|
|||
ret.push_back('"');
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string ConvertError(DWORD error_code)
|
||||
{
|
||||
wchar_t buffer[320];
|
||||
|
||||
auto r = FormatMessageW(
|
||||
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
nullptr, error_code, 0, buffer, ARRLEN(buffer) - 1, nullptr);
|
||||
if (!r)
|
||||
return std::to_string(error_code);
|
||||
|
||||
if (!buffer[0]) // should not happen normally
|
||||
return "?";
|
||||
return wide_to_utf8(buffer);
|
||||
}
|
||||
#endif
|
||||
|
||||
int mt_snprintf(char *buf, const size_t buf_size, const char *fmt, ...)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue