Skip to content

Commit 4c56026

Browse files
committed
fixup
1 parent 9116f40 commit 4c56026

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/string.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,16 +1400,17 @@ const char *StrErrorDumper::Get(int errornum)
14001400
return this->buf;
14011401
}
14021402
#else
1403+
struct StrErrorRHelper {
1404+
static bool Success(char *result) { return true; } ///< GNU-specific
1405+
static bool Success(int result) { return result == 0; } ///< XSI-compliant
1406+
1407+
static const char *GetString(char *result, const char *buffer) { return result; } ///< GNU-specific
1408+
static const char *GetString(int result, const char *buffer) { return buffer; } ///< XSI-compliant
1409+
};
1410+
14031411
auto result = strerror_r(errornum, this->buf, lengthof(this->buf));
1404-
static_assert(std::is_same_v<decltype(result), char *> || std::is_same_v<decltype(result), int>);
1405-
if constexpr (std::is_same_v<decltype(result), char *>) {
1406-
/* GNU-specific */
1407-
return result;
1408-
} else {
1409-
/* XSI-compliant */
1410-
if (result == 0) {
1411-
return this->buf;
1412-
}
1412+
if (StrErrorRHelper::Success(result)) {
1413+
return StrErrorRHelper::GetString(result, this->buf);
14131414
}
14141415
#endif
14151416

0 commit comments

Comments
 (0)