Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
JGRennison committed Jun 10, 2024
1 parent 9116f40 commit 4c56026
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1400,16 +1400,17 @@ const char *StrErrorDumper::Get(int errornum)
return this->buf;
}
#else
struct StrErrorRHelper {
static bool Success(char *result) { return true; } ///< GNU-specific
static bool Success(int result) { return result == 0; } ///< XSI-compliant

static const char *GetString(char *result, const char *buffer) { return result; } ///< GNU-specific
static const char *GetString(int result, const char *buffer) { return buffer; } ///< XSI-compliant
};

auto result = strerror_r(errornum, this->buf, lengthof(this->buf));
static_assert(std::is_same_v<decltype(result), char *> || std::is_same_v<decltype(result), int>);
if constexpr (std::is_same_v<decltype(result), char *>) {
/* GNU-specific */
return result;
} else {
/* XSI-compliant */
if (result == 0) {
return this->buf;
}
if (StrErrorRHelper::Success(result)) {
return StrErrorRHelper::GetString(result, this->buf);
}
#endif

Expand Down

0 comments on commit 4c56026

Please sign in to comment.