From a7ed7530dfc3b359d808521b8daed43b831a4a6d Mon Sep 17 00:00:00 2001 From: hoisie Date: Fri, 3 Dec 2021 12:31:50 -0800 Subject: [PATCH] Update platformStrError to work in Windows PiperOrigin-RevId: 413996788 --- .../include/nativehelper/JNIHelp.h | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/nativeruntime/cpp/libnativehelper/include/nativehelper/JNIHelp.h b/nativeruntime/cpp/libnativehelper/include/nativehelper/JNIHelp.h index cf03f66e15a..1dd44b60268 100644 --- a/nativeruntime/cpp/libnativehelper/include/nativehelper/JNIHelp.h +++ b/nativeruntime/cpp/libnativehelper/include/nativehelper/JNIHelp.h @@ -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,