Hello!
Many years ago I have found some bugs are prevented build of libFLAC on
some MinGW toolchains and I made my own patch to fix that.
- The `_wutime64()` call may absent. For this case I using the
`_wutime()` call as a fallback when _wutime64() is unavailable.
- `_stricmp` and `_strnicmp` are also may fail. Therefore it's prefer to
use `stricmp` and `strnicmp` (without `_` prefix) on MinGW toolchains.
I have added a small check into CMake build, however, I didn't touched
Automake and MSVC builds yet. Anyway, for MSVC builds you can simply
define the `HAVE_WUTIME64` macro if MSVC toolchains are always have that
call available.
I have included a patch and a simple test program which tests
availability of `_wutime64()` call.
Can you apply my patch or make a different fix of this issue?
Best regards,
Vitaly Novichkov "Wohlstand"
#ifdef _WIN32
#undef NO_OLDNAMES
#undef _NO_OLDNAMES
#endif
#include <io.h>
#include <sys/utime.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/utime.h>
#include <windows.h>
int main()
{
wchar_t *wname = L"dummy.txt";
struct __utimbuf64 ut;
ut.actime = 0;
ut.modtime = 0;
return _wutime64(wname, &ut);
}
>From 65314fdc13ebc227f5d85adafed7fabe9cd322f5 Mon Sep 17 00:00:00 2001
From: Wohlstand <ad...@wohlnet.ru>
Date: Wed, 14 Aug 2019 14:07:59 +0300
Subject: [PATCH] Build fix for some MinGW toolchains - _wutime64() call may
absent and build will fail - it's preferred to use `str*cmp` rather
`_str*cmp` as `_str*cmp` also may absent and build also will fail
---
CMakeLists.txt | 2 ++
config.cmake.h.in | 3 +++
include/share/compat.h | 9 +++++++--
include/share/windows_unicode_filenames.h | 8 ++++++++
src/libFLAC/windows_unicode_filenames.c | 4 ++--
5 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 66f4db24..0d91b4c1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -50,6 +50,8 @@ check_include_file("x86intrin.h" FLAC__HAS_X86INTRIN)
check_function_exists(fseeko HAVE_FSEEKO)
+check_c_source_compiles("#ifdef _WIN32\n#undef NO_OLDNAMES\n#undef _NO_OLDNAMES\n#endif\n#include <sys/utime.h>\n int main() { wchar_t *wname = L\"dummy.txt\"; struct __utimbuf64 ut; ut.actime = 0; ut.modtime = 0; return _wutime64(wname, &ut); }" HAVE_WUTIME64)
+
check_c_source_compiles("int main() { return __builtin_bswap16 (0) ; }" HAVE_BSWAP16)
check_c_source_compiles("int main() { return __builtin_bswap32 (0) ; }" HAVE_BSWAP32)
diff --git a/config.cmake.h.in b/config.cmake.h.in
index 1d96f426..fb6ed5f0 100644
--- a/config.cmake.h.in
+++ b/config.cmake.h.in
@@ -125,6 +125,9 @@
/* Define to 1 if you have the <unistd.h> header file. */
#cmakedefine HAVE_UNISTD_H
+/* Define to 1 if _wutime64() exists and is declared */
+#cmakedefine HAVE_WUTIME64
+
/* Define to 1 if you have the <x86intrin.h> header file. */
#cmakedefine HAVE_X86INTRIN_H
diff --git a/include/share/compat.h b/include/share/compat.h
index f3041655..5caebe90 100644
--- a/include/share/compat.h
+++ b/include/share/compat.h
@@ -88,8 +88,13 @@
#define FLAC__U64L(x) x##ULL
#if defined _MSC_VER || defined __MINGW32__
-#define FLAC__STRCASECMP _stricmp
-#define FLAC__STRNCASECMP _strnicmp
+# if defined _MSC_VER
+# define FLAC__STRCASECMP _stricmp
+# define FLAC__STRNCASECMP _strnicmp
+# else
+# define FLAC__STRCASECMP stricmp
+# define FLAC__STRNCASECMP strnicmp
+# endif
#elif defined __BORLANDC__
#define FLAC__STRCASECMP stricmp
#define FLAC__STRNCASECMP strnicmp
diff --git a/include/share/windows_unicode_filenames.h b/include/share/windows_unicode_filenames.h
index 526b30d5..8121cdec 100644
--- a/include/share/windows_unicode_filenames.h
+++ b/include/share/windows_unicode_filenames.h
@@ -43,6 +43,14 @@
extern "C" {
#endif
+#ifdef HAVE_WUTIME64
+#define FLAC_struct_utime __utimbuf64
+#define FLAC_utime _wutime64
+#else
+#define FLAC_struct_utime _utimbuf
+#define FLAC_utime _wutime
+#endif
+
void flac_internal_set_utf8_filenames(FLAC__bool flag);
FLAC__bool flac_internal_get_utf8_filenames(void);
#define flac_set_utf8_filenames flac_internal_set_utf8_filenames
diff --git a/src/libFLAC/windows_unicode_filenames.c b/src/libFLAC/windows_unicode_filenames.c
index 78550087..41ecc661 100644
--- a/src/libFLAC/windows_unicode_filenames.c
+++ b/src/libFLAC/windows_unicode_filenames.c
@@ -133,13 +133,13 @@ int flac_internal_utime_utf8(const char *filename, struct utimbuf *times)
return utime(filename, times);
} else {
wchar_t *wname;
- struct __utimbuf64 ut;
+ struct FLAC_struct_utime ut;
int ret;
if (!(wname = wchar_from_utf8(filename))) return -1;
ut.actime = times->actime;
ut.modtime = times->modtime;
- ret = _wutime64(wname, &ut);
+ ret = FLAC_utime(wname, &ut);
free(wname);
return ret;
--
2.17.1
_______________________________________________
flac-dev mailing list
flac-dev@xiph.org
http://lists.xiph.org/mailman/listinfo/flac-dev