mirror of
https://github.com/rui314/mold.git
synced 2024-10-05 00:57:08 +03:00
Use strerror_r() instead of strerror()
I have no idea why, but 2b818dbe44
made
mold's chrome link time slower by ~8%. This patch removes the use
of std::mutex.
This commit is contained in:
parent
4033b53d7f
commit
ce2fee10b5
21
main.cc
21
main.cc
@ -7,12 +7,21 @@
|
||||
namespace mold {
|
||||
|
||||
std::string_view errno_string() {
|
||||
// There's a thread-safe version of strerror() (strerror_r()), but
|
||||
// GNU and POSIX define that function differently. To avoid the mess,
|
||||
// we simply use strerror() with a lock.
|
||||
static std::mutex mu;
|
||||
std::lock_guard lock(mu);
|
||||
return strerror(errno);
|
||||
static thread_local char buf[200];
|
||||
|
||||
// There are two incompatible strerror_r implementations as follows.
|
||||
//
|
||||
// GNU: char *strerror_r(int, char *, size_t)
|
||||
// POSIX: int strerror_r(int, char *, size_t)
|
||||
//
|
||||
// GNU version may write an error message to a buffer other than the
|
||||
// given one and returns a pointer to the error message. POSIX version
|
||||
// always write an error message to a given buffer.
|
||||
|
||||
if (std::is_same<decltype(strerror_r(errno, buf, sizeof(buf))), char *>::value)
|
||||
return strerror_r(errno, buf, sizeof(buf));
|
||||
strerror_r(errno, buf, sizeof(buf));
|
||||
return buf;
|
||||
}
|
||||
|
||||
#ifdef GIT_HASH
|
||||
|
Loading…
Reference in New Issue
Block a user