diff options
author | oy <tom_adams@web.de> | 2023-06-13 22:26:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-13 22:26:47 +0200 |
commit | d736488618a7b8bffd8a8f57c5a5a0a00b759ea5 (patch) | |
tree | 59577b91321439d1cc7bfe105b990c9c9f985c51 | |
parent | 134f0d56f68ae90d876b958dfcfa7a18bb6febd0 (diff) | |
parent | c955f19494b8ba3bde993141a68c8705309c081a (diff) |
Merge pull request #3127 from Robyt3/MinGW-fixes
Fix build and warnings on MinGW
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/base/system.c | 25 |
2 files changed, 16 insertions, 13 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 36ca113b7..6704b3385 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -138,8 +138,7 @@ endfunction() if(NOT MSVC) # Protect the stack pointer. - # -fstack-protector-all doesn't work on MinGW. - add_c_compiler_flag_if_supported(OUR_FLAGS -fstack-protector-strong) + add_c_compiler_flag_if_supported(OUR_FLAGS -fstack-protector-all) # Protect the stack from clashing. add_c_compiler_flag_if_supported(OUR_FLAGS -fstack-clash-protection) @@ -2118,6 +2117,7 @@ foreach(target ${TARGETS_OWN}) target_compile_options(${target} PRIVATE /wd4800) # Implicit conversion of int to bool. endif() if(TARGET_OS STREQUAL "windows") + target_compile_definitions(${target} PRIVATE _WIN32_WINNT=0x0501) target_compile_definitions(${target} PRIVATE UNICODE) # Windows headers target_compile_definitions(${target} PRIVATE _UNICODE) # C-runtime endif() diff --git a/src/base/system.c b/src/base/system.c index 968db569c..339dfa813 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -313,12 +313,12 @@ IOHANDLE io_open_impl(const char *filename, int flags) { dbg_assert(flags == (IOFLAG_READ | IOFLAG_SKIP_BOM) || flags == IOFLAG_READ || flags == IOFLAG_WRITE || flags == IOFLAG_APPEND, "flags must be read, read+skipbom, write or append"); #if defined(CONF_FAMILY_WINDOWS) - WCHAR wBuffer[IO_MAX_PATH_LENGTH]; if((flags & IOFLAG_READ) != 0) { // check for filename case sensitive WIN32_FIND_DATAW finddata; HANDLE handle; + WCHAR wBuffer[IO_MAX_PATH_LENGTH]; char buffer[IO_MAX_PATH_LENGTH]; int length = str_length(filename); @@ -339,11 +339,13 @@ IOHANDLE io_open_impl(const char *filename, int flags) } if(flags == IOFLAG_WRITE) { + WCHAR wBuffer[IO_MAX_PATH_LENGTH]; MultiByteToWideChar(CP_UTF8, 0, filename, -1, wBuffer, sizeof(wBuffer) / sizeof(WCHAR)); return (IOHANDLE)_wfsopen(wBuffer, L"wb", _SH_DENYNO); } if(flags == IOFLAG_APPEND) { + WCHAR wBuffer[IO_MAX_PATH_LENGTH]; MultiByteToWideChar(CP_UTF8, 0, filename, -1, wBuffer, sizeof(wBuffer) / sizeof(WCHAR)); return (IOHANDLE)_wfsopen(wBuffer, L"ab", _SH_DENYNO); } @@ -1523,7 +1525,7 @@ static inline time_t filetime_to_unixtime(LPFILETIME filetime) li.QuadPart -= 11644473600LL; // Windows epoch is in the past t = li.QuadPart; - return t == li.QuadPart ? t : (time_t)-1; + return t == (time_t)li.QuadPart ? t : (time_t)-1; } #endif @@ -1605,10 +1607,10 @@ void fs_listdir_fileinfo(const char *dir, FS_LISTDIR_CALLBACK_FILEINFO cb, int t /* add all the entries */ do { + CFsFileInfo info; WideCharToMultiByte(CP_UTF8, 0, finddata.cFileName, -1, buffer2, sizeof(buffer2), NULL, NULL); str_copy(buffer+length, buffer2, (int)sizeof(buffer)-length); - CFsFileInfo info; info.m_pName = buffer2; info.m_TimeCreated = filetime_to_unixtime(&finddata.ftCreationTime); info.m_TimeModified = filetime_to_unixtime(&finddata.ftLastWriteTime); @@ -1757,8 +1759,9 @@ int fs_is_dir(const char *path) { #if defined(CONF_FAMILY_WINDOWS) WCHAR wPath[IO_MAX_PATH_LENGTH]; + DWORD attributes; MultiByteToWideChar(CP_UTF8, 0, path, -1, wPath, sizeof(wPath) / sizeof(WCHAR)); - DWORD attributes = GetFileAttributesW(wPath); + attributes = GetFileAttributesW(wPath); return attributes != INVALID_FILE_ATTRIBUTES && (attributes & FILE_ATTRIBUTE_DIRECTORY) ? 1 : 0; #else struct stat sb; @@ -2102,9 +2105,8 @@ void str_append(char *dst, const char *src, int dst_size) void str_copy(char *dst, const char *src, int dst_size) { dbg_assert(dst_size > 0, "dst_size invalid"); - - strncpy(dst, src, dst_size-1); - dst[dst_size-1] = 0; /* assure null termination */ + dst[0] = '\0'; + strncat(dst, src, dst_size - 1); } void str_truncate(char *dst, int dst_size, const char *src, int truncation_len) @@ -2928,11 +2930,12 @@ void cmdline_fix(int *argc, const char ***argv) { #if defined(CONF_FAMILY_WINDOWS) int wide_argc = 0; + int total_size = 0; + int remaining_size; + char **new_argv; WCHAR **wide_argv = CommandLineToArgvW(GetCommandLineW(), &wide_argc); dbg_assert(wide_argv != NULL, "CommandLineToArgvW failure"); - int total_size = 0; - for(int i = 0; i < wide_argc; i++) { int size = WideCharToMultiByte(CP_UTF8, 0, wide_argv[i], -1, NULL, 0, NULL, NULL); @@ -2940,11 +2943,11 @@ void cmdline_fix(int *argc, const char ***argv) total_size += size; } - char **new_argv = (char **)malloc((wide_argc + 1) * sizeof(*new_argv)); + new_argv = (char **)malloc((wide_argc + 1) * sizeof(*new_argv)); new_argv[0] = (char *)malloc(total_size); mem_zero(new_argv[0], total_size); - int remaining_size = total_size; + remaining_size = total_size; for(int i = 0; i < wide_argc; i++) { int size = WideCharToMultiByte(CP_UTF8, 0, wide_argv[i], -1, new_argv[i], remaining_size, NULL, NULL); |