1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-11 13:06:59 +03:00

Attempt to fix CI

This commit is contained in:
Rui Ueyama 2024-03-20 18:41:57 +09:00
parent fd8fb73492
commit 6fe4f23074
2 changed files with 22 additions and 4 deletions

View File

@ -49,12 +49,30 @@ void cleanup() {
unlink(output_tmpfile);
}
#ifdef _WIN32
std::string errno_string() {
LPVOID buf;
DWORD dw = GetLastError();
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&buf, 0, nullptr);
std::string ret = buf;
LocalFree(buf);
return ret;
}
#else
std::string errno_string() {
// strerror is not thread-safe, so guard it with a lock.
static std::mutex mu;
std::scoped_lock lock(mu);
return strerror(errno);
}
#endif
// Returns the path of the mold executable itself
std::string get_self_path() {

View File

@ -10,7 +10,7 @@ MappedFile *open_file_impl(const std::string &path, std::string &error) {
if (fd == INVALID_HANDLE_VALUE) {
auto err = GetLastError();
if (err != ERROR_FILE_NOT_FOUND)
error = "opening " + path + " failed: " + err;
error = "opening " + path + " failed: " + errno_string();
return nullptr;
}
@ -23,7 +23,7 @@ MappedFile *open_file_impl(const std::string &path, std::string &error) {
DWORD size_lo = GetFileSize(fd, &size_hi);
if (size_lo == INVALID_FILE_SIZE) {
error = path + ": GetFileSize failed: " + GetLastError();
error = path + ": GetFileSize failed: " + errno_string();
return nullptr;
}
@ -37,7 +37,7 @@ MappedFile *open_file_impl(const std::string &path, std::string &error) {
if (size > 0) {
HANDLE h = CreateFileMapping(fd, nullptr, PAGE_READONLY, 0, size, nullptr);
if (!h) {
error = path + ": CreateFileMapping failed: " + GetLastError();
error = path + ": CreateFileMapping failed: " + errno_string();
return nullptr;
}
@ -45,7 +45,7 @@ MappedFile *open_file_impl(const std::string &path, std::string &error) {
CloseHandle(h);
if (!mf->data) {
error = path + ": MapViewOfFile failed: " + GetLastError();
error = path + ": MapViewOfFile failed: " + errno_string();
return nullptr;
}
}