-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.cpp
More file actions
45 lines (32 loc) · 915 Bytes
/
Copy pathutils.cpp
File metadata and controls
45 lines (32 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "utils.hpp"
#include "windows_lean.h"
#include <string>
#include <sstream>
#include "common/IDebugLog.h"
std::string get_last_error_message(size_t max_size) {
std::string output(max_size, '\0');
get_last_error_message(output);
return output;
}
void get_last_error_message(std::string& output) {
if (output.empty())
return;
size_t written_count = FormatMessageA(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
&output[0],
output.size(),
NULL);
output.resize(written_count);
}
void fatal_error(const char* message, bool include_last_error) {
std::stringstream ss;
if (message != NULL)
ss << message << '\n';
if (include_last_error)
ss << "Last error:\n" << get_last_error_message();
std::string output = ss.str();
_ERROR(output.c_str());
}