android + common: fix warnings
This commit is contained in:
parent
8eb89c260d
commit
946a32d793
3 changed files with 29 additions and 44 deletions
|
@ -56,35 +56,6 @@ std::condition_variable running_cv;
|
|||
|
||||
} // Anonymous namespace
|
||||
|
||||
static bool DisplayAlertMessage(const char* caption, const char* text, bool yes_no) {
|
||||
JNIEnv* env = IDCache::GetEnvForThread();
|
||||
|
||||
// Execute the Java method.
|
||||
jboolean result = env->CallStaticBooleanMethod(
|
||||
IDCache::GetNativeLibraryClass(), IDCache::GetDisplayAlertMsg(), ToJString(env, caption),
|
||||
ToJString(env, text), yes_no ? JNI_TRUE : JNI_FALSE);
|
||||
|
||||
return result != JNI_FALSE;
|
||||
}
|
||||
|
||||
static std::string DisplayAlertPrompt(const char* caption, const char* text, int buttonConfig) {
|
||||
JNIEnv* env = IDCache::GetEnvForThread();
|
||||
|
||||
jstring value = reinterpret_cast<jstring>(env->CallStaticObjectMethod(
|
||||
IDCache::GetNativeLibraryClass(), IDCache::GetDisplayAlertPrompt(), ToJString(env, caption),
|
||||
ToJString(env, text), buttonConfig));
|
||||
|
||||
return GetJString(env, value);
|
||||
}
|
||||
|
||||
static int AlertPromptButton() {
|
||||
JNIEnv* env = IDCache::GetEnvForThread();
|
||||
|
||||
// Execute the Java method.
|
||||
return static_cast<int>(env->CallStaticIntMethod(IDCache::GetNativeLibraryClass(),
|
||||
IDCache::GetAlertPromptButton()));
|
||||
}
|
||||
|
||||
static jobject ToJavaCoreError(Core::System::ResultStatus result) {
|
||||
static const std::map<Core::System::ResultStatus, const char*> CoreErrorNameMap{
|
||||
{Core::System::ResultStatus::ErrorSystemFiles, "ErrorSystemFiles"},
|
||||
|
|
|
@ -102,12 +102,11 @@ static void StripTailDirSlashes(std::string& fname) {
|
|||
}
|
||||
|
||||
bool Exists(const std::string& filename) {
|
||||
struct stat file_info;
|
||||
|
||||
std::string copy(filename);
|
||||
StripTailDirSlashes(copy);
|
||||
|
||||
#ifdef _WIN32
|
||||
struct stat file_info;
|
||||
// Windows needs a slash to identify a driver root
|
||||
if (copy.size() != 0 && copy.back() == ':')
|
||||
copy += DIR_SEP_CHR;
|
||||
|
@ -116,6 +115,7 @@ bool Exists(const std::string& filename) {
|
|||
#elif ANDROID
|
||||
int result = AndroidStorage::FileExists(filename) ? 0 : -1;
|
||||
#else
|
||||
struct stat file_info;
|
||||
int result = stat(copy.c_str(), &file_info);
|
||||
#endif
|
||||
|
||||
|
@ -699,7 +699,7 @@ static const std::string& GetHomeDirectory() {
|
|||
* @return The directory path
|
||||
* @sa http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||
*/
|
||||
static const std::string GetUserDirectory(const std::string& envvar) {
|
||||
[[maybe_unused]] static const std::string GetUserDirectory(const std::string& envvar) {
|
||||
const char* directory = getenv(envvar.c_str());
|
||||
|
||||
std::string user_dir;
|
||||
|
|
|
@ -16,19 +16,33 @@
|
|||
// Call directly after the command or use the error num.
|
||||
// This function might change the error code.
|
||||
std::string GetLastErrorMsg() {
|
||||
constexpr std::size_t buff_size = 255;
|
||||
char err_str[buff_size];
|
||||
std::size_t msg_len;
|
||||
|
||||
#ifdef _WIN32
|
||||
msg_len =
|
||||
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(),
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), err_str, buff_size, nullptr);
|
||||
LPSTR err_str;
|
||||
|
||||
DWORD res = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
nullptr, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
reinterpret_cast<LPSTR>(&err_str), 1, nullptr);
|
||||
if (!res) {
|
||||
return "(FormatMessageA failed to format error)";
|
||||
}
|
||||
std::string ret(err_str);
|
||||
LocalFree(err_str);
|
||||
return ret;
|
||||
#else
|
||||
char err_str[255];
|
||||
#if (defined(__GLIBC__) || __ANDROID_API__ >= 23) && \
|
||||
(_GNU_SOURCE || (_POSIX_C_SOURCE < 200112L && _XOPEN_SOURCE < 600))
|
||||
// Thread safe (GNU-specific)
|
||||
const char* str = strerror_r(errno, err_str, sizeof(err_str));
|
||||
return std::string(str);
|
||||
#else
|
||||
// Thread safe (XSI-compliant)
|
||||
strerror_r(errno, err_str, buff_size);
|
||||
msg_len = strnlen(err_str, buff_size);
|
||||
#endif
|
||||
|
||||
return std::string(err_str, msg_len);
|
||||
int second_err = strerror_r(errno, err_str, sizeof(err_str));
|
||||
if (second_err != 0) {
|
||||
return "(strerror_r failed to format error)";
|
||||
}
|
||||
return std::string(err_str);
|
||||
#endif // GLIBC etc.
|
||||
#endif // _WIN32
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue