[gtk/gtk-2-24.win.fixes] gtk/gtkiconcache.c: Fix running on GLib-2.57.3 or later on Windows
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/gtk-2-24.win.fixes] gtk/gtkiconcache.c: Fix running on GLib-2.57.3 or later on Windows
- Date: Thu, 20 Dec 2018 08:51:51 +0000 (UTC)
commit bb7cefb341a1e954748b4b7c94768420ab7fe5d7
Author: Chun-wei Fan <fanchunwei src gnome org>
Date: Thu Dec 20 16:44:42 2018 +0800
gtk/gtkiconcache.c: Fix running on GLib-2.57.3 or later on Windows
In GLib-2.57.3 and later, GStatBuf may not be a struct stat on Windows,
depending on the architecture and the compiler used, so we can't just
call fstat() on the GStatBuf.
Instead, we need to use the correct CRT function to call on the
GStatBuf, which is as follows:
-_fstat32() for Windows 32-bit builds on mingw-w64 and MSVC
-_fstat64() for Windows 64-bit builds on mingw-w64
-stat() for Windows 64-bit builds on MSVC, and on all other platforms.
gtk/gtkiconcache.c | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkiconcache.c b/gtk/gtkiconcache.c
index 143f8f14b8..275f31a4d5 100644
--- a/gtk/gtkiconcache.c
+++ b/gtk/gtkiconcache.c
@@ -111,9 +111,33 @@ _gtk_icon_cache_new_for_path (const gchar *path)
if (fd < 0)
goto done;
- if (fstat (fd, &st) < 0 || st.st_size < 4)
+ /* We need to know the correct function to call for the GStatBuf st we are using here,
+ * because GStatBuf may not be stat on Windows
+ */
+#ifdef G_OS_WIN32
+ if (GLIB_CHECK_VERSION (2, 57, 3))
+ {
+# ifdef __MINGW64_VERSION_MAJOR
+# ifdef _WIN64
+# define gtk_fstat _fstat64
+# else
+# define gtk_fstat _fstat32
+# endif
+# elif defined (_MSC_VER) && !defined (_WIN64)
+# define gtk_fstat _fstat32
+# endif
+ }
+#endif
+
+#ifndef gtk_fstat
+#define gtk_fstat fstat
+#endif
+
+ if (gtk_fstat (fd, &st) < 0 || st.st_size < 4)
goto done;
+#undef gtk_fstat
+
/* Verify cache is uptodate */
if (st.st_mtime < path_st.st_mtime)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]