Skip to content

Commit

Permalink
Use strerror() instead of strerror_r()
Browse files Browse the repository at this point in the history
This should fix the build on Android.
Fixes rui314#231
  • Loading branch information
rui314 committed Jan 2, 2022
1 parent 19dce53 commit 2b818db
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@
namespace mold {

std::string_view errno_string() {
static thread_local char buf[200];
#if _GNU_SOURCE
// The GNU version of strerror_r() returns a char * and may completely ignore
// buf
return strerror_r(errno, buf, sizeof(buf));
#else
// The POSIX.1-2001-compliant version of strerror_r() returns an int and
// writes the string into buf
return !strerror_r(errno, buf, sizeof(buf)) ? buf : "Unknown error";
#endif
// 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);
}

#ifdef GIT_HASH
Expand Down

0 comments on commit 2b818db

Please sign in to comment.