summaryrefslogtreecommitdiff
path: root/libs/pbd
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2017-10-18 17:53:02 +0200
committerRobin Gareus <robin@gareus.org>2017-10-18 17:54:39 +0200
commit5c6e2b580280a750660b6a4d94c3886fdac5a247 (patch)
treefa912a934028fcea12e5c1686c4af82a90d38ec5 /libs/pbd
parent0c59ba649ef11236fca34b2a976fcee7309b9eb5 (diff)
Fix g_stat() for 64bit windows/mingw64
Diffstat (limited to 'libs/pbd')
-rw-r--r--libs/pbd/pbd/gstdio_compat.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/libs/pbd/pbd/gstdio_compat.h b/libs/pbd/pbd/gstdio_compat.h
index 743081539a..1f48641ee3 100644
--- a/libs/pbd/pbd/gstdio_compat.h
+++ b/libs/pbd/pbd/gstdio_compat.h
@@ -25,4 +25,45 @@ pbd_g_stat(const gchar *filename, GStatBufW32 *buf)
# define g_lstat pbd_g_stat
#endif
+/* 64bit mingw -- use _mingw_stat64.h
+ *
+ * glib-2.42.0 wrongly uses _wstat() with 'struct stat' (only MSVC is special cased),
+ * while the windows API is
+ * int _wstat(const wchar_t*, struct _stat*)
+ * note that struct _stat != struct stat;
+ */
+#if defined(_WIN32) && !defined(_MSC_VER) && defined(_WIN64)
+#include <windows.h>
+#include <errno.h>
+#include <wchar.h>
+
+typedef struct _stat GStatBufW64;
+static inline int
+pbd_g_stat(const gchar* filename, GStatBufW64* buf)
+{
+ gunichar2* wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
+ if (wfilename == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ int len = wcslen ((wchar_t*)wfilename);
+ while (len > 0 && G_IS_DIR_SEPARATOR (wfilename[len-1])) {
+ --len;
+ }
+ if (len > 0 && (!g_path_is_absolute (filename) || len > g_path_skip_root (filename) - filename)) {
+ wfilename[len] = '\0';
+ }
+
+ int retval = _wstat ((wchar_t*)wfilename, buf);
+ int save_errno = errno;
+ g_free (wfilename);
+ errno = save_errno;
+ return retval;
+}
+# define GStatBuf GStatBufW64
+# define g_stat pbd_g_stat
+# define g_lstat pbd_g_stat
+#endif
+
#endif /* __pbd_gstdio_compat_h__ */