cross-win32: hide glib bug of mismatched g_stat and GStatBuf for win32 (not win64)

Thu, 17 Apr 2014 08:19:13 +0200

author
Tomasz Wasilczyk <twasilczyk@pidgin.im>
date
Thu, 17 Apr 2014 08:19:13 +0200
changeset 35867
b6f09494adda
parent 35866
5d317ffcece3
child 35868
7ec185592a12

cross-win32: hide glib bug of mismatched g_stat and GStatBuf for win32 (not win64)

libpurple/glibcompat.h file | annotate | diff | comparison | revisions
libpurple/util.c file | annotate | diff | comparison | revisions
libpurple/win32/libc_interface.h file | annotate | diff | comparison | revisions
--- a/libpurple/glibcompat.h	Thu Apr 17 06:38:02 2014 +0200
+++ b/libpurple/glibcompat.h	Thu Apr 17 08:19:13 2014 +0200
@@ -148,6 +148,18 @@
 #endif /* < 2.36.0 */
 
 
+/* glib's definition of g_stat+GStatBuf seems to be broken on 32-bit windows,
+ * so instead of relying on it, we'll define our own macros.
+ */
+#if defined(_WIN32) && !defined(_MSC_VER) && !defined(_WIN64)
+#  include <glib/gstdio.h>
+typedef struct _stat64 GStatBuf64;
+#  define GStatBuf GStatBuf64
+#  undef g_stat
+#  define g_stat _stat64
+#endif
+
+
 #ifdef __clang__
 
 #undef G_GNUC_BEGIN_IGNORE_DEPRECATIONS
--- a/libpurple/util.c	Thu Apr 17 06:38:02 2014 +0200
+++ b/libpurple/util.c	Thu Apr 17 08:19:13 2014 +0200
@@ -3095,12 +3095,17 @@
 		return FALSE;
 	}
 	/* Use stat to be absolutely sure. */
-	if ((g_stat(filename_temp, &st) == -1) || (st.st_size != (off_t)real_size))
-	{
+	if (g_stat(filename_temp, &st) == -1) {
 		purple_debug_error("util", "Error writing data to file %s: "
-				   "Incomplete file written; is your disk "
-				   "full?\n",
-				   filename_temp);
+			"couldn't g_stat file", filename_temp);
+		g_free(filename_temp);
+		return FALSE;
+	}
+	if (st.st_size != (off_t)real_size) {
+		purple_debug_error("util", "Error writing data to file %s: "
+			"Incomplete file written (%" G_GSIZE_FORMAT " != %"
+			G_GSIZE_FORMAT "); is your disk full?",
+			filename_temp, (gsize)st.st_size, real_size);
 		g_free(filename_temp);
 		return FALSE;
 	}
--- a/libpurple/win32/libc_interface.h	Thu Apr 17 06:38:02 2014 +0200
+++ b/libpurple/win32/libc_interface.h	Thu Apr 17 08:19:13 2014 +0200
@@ -28,6 +28,7 @@
 #include <errno.h>
 #include "libc_internal.h"
 #include <glib.h>
+#include "glibcompat.h"
 
 #ifdef __cplusplus
 extern "C" {

mercurial