Skip to content

Commit

Permalink
Update platformStrError to work in Windows
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 413996788
  • Loading branch information
hoisie committed Dec 6, 2021
1 parent bcb31db commit a7ed753
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions nativeruntime/cpp/libnativehelper/include/nativehelper/JNIHelp.h
Expand Up @@ -89,26 +89,22 @@ struct [[maybe_unused]] ExpandableString {
return ExpandableStringAppend(s, text);
}

[[maybe_unused]] inline char* safe_strerror(
char* (*strerror_r_method)(int, char*, size_t), int errnum, char* buf,
size_t buflen) {
return strerror_r_method(errnum, buf, buflen);
}

[[maybe_unused]] inline char* safe_strerror(int (*strerror_r_method)(int, char*,
size_t),
int errnum, char* buf,
size_t buflen) {
int rc = strerror_r_method(errnum, buf, buflen);
[[maybe_unused]] inline const char* platformStrError(int errnum, char* buf,
size_t buflen) {
#ifdef _WIN32
strerror_s(buf, buflen, errnum);
return buf;
#elif defined(__USE_GNU)
// char *strerror_r(int errnum, char *buf, size_t buflen); /* GNU-specific */
return strerror_r(errnum, buf, buflen);
#else
// int strerror_r(int errnum, char *buf, size_t buflen); /* XSI-compliant */
int rc = strerror_r(errnum, buf, buflen);
if (rc != 0) {
snprintf(buf, buflen, "errno %d", errnum);
}
return buf;
}

[[maybe_unused]] static const char* platformStrError(int errnum, char* buf,
size_t buflen) {
return safe_strerror(strerror_r, errnum, buf, buflen);
#endif
}

[[maybe_unused]] static jmethodID FindMethod(JNIEnv* env, const char* className,
Expand Down

0 comments on commit a7ed753

Please sign in to comment.