Skip to content
Permalink
Browse files

refs #21, dropping macro based detection and using generic aproach.

  • Loading branch information...
gulrak committed Jun 17, 2019
1 parent 091c086 commit 8e824cedefd3a660179ff0208b34be75635cebd8
Showing with 15 additions and 7 deletions.
  1. +15 −7 include/ghc/filesystem.hpp
@@ -172,7 +172,7 @@
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

// ghc::filesystem version in decimal (major * 10000 + minor * 100 + patch)
#define GHC_FILESYSTEM_VERSION 10200L
#define GHC_FILESYSTEM_VERSION 10201L

namespace ghc {
namespace filesystem {
@@ -1514,6 +1514,19 @@ GHC_INLINE bool equals_simple_insensitive(const char* str1, const char* str2)
#endif
}

GHC_INLINE const char* strerror_adapter(char* gnu, char*)
{
return gnu;
}

GHC_INLINE const char* strerror_adapter(int posix, char* buffer)
{
if(posix) {
return "Error in strerror_r!";
}
return buffer;
}

template <typename ErrorNumber>
GHC_INLINE std::string systemErrorText(ErrorNumber code = 0)
{
@@ -1524,14 +1537,9 @@ GHC_INLINE std::string systemErrorText(ErrorNumber code = 0)
std::string msg = toUtf8(std::wstring((LPWSTR)msgBuf));
LocalFree(msgBuf);
return msg;
#elif defined(GHC_OS_MACOS) || ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !defined(_GNU_SOURCE)) || (defined(GHC_OS_ANDROID) && __ANDROID_API__ < 23)
char buffer[512];
int rc = strerror_r(code ? code : errno, buffer, sizeof(buffer));
return rc == 0 ? (const char*)buffer : "Error in strerror_r!";
#else
char buffer[512];
char* msg = strerror_r(code ? code : errno, buffer, sizeof(buffer));
return msg ? msg : buffer;
return strerror_adapter(strerror_r(code ? code : errno, buffer, sizeof(buffer)), buffer);
#endif
}

0 comments on commit 8e824ce

Please sign in to comment.
You can’t perform that action at this time.