1 /* glib mingw64/win32 compatibility
3 * see http://pidgin.im/pipermail/devel/2014-April/023475.html
4 * and https://pidgin.im/pipermail/commits/2014-April/025031.html
5 * http://tracker.ardour.org/view.php?id=6575
8 #ifndef __pbd_gstdio_compat_h__
9 #define __pbd_gstdio_compat_h__
11 #include <glib/gstdio.h>
13 /* glib's definition of g_stat+GStatBuf is broken for mingw64-w32
14 * (and possibly other 32-bit windows)
16 #if defined(_WIN32) && !defined(_MSC_VER) && !defined(_WIN64)
17 typedef struct _stat GStatBufW32;
19 pbd_g_stat(const gchar *filename, GStatBufW32 *buf)
21 return g_stat(filename, (GStatBuf*)buf);
23 # define GStatBuf GStatBufW32
24 # define g_stat pbd_g_stat
25 # define g_lstat pbd_g_stat
28 /* 64bit mingw -- use _mingw_stat64.h
30 * glib-2.42.0 wrongly uses _wstat() with 'struct stat' (only MSVC is special cased),
31 * while the windows API is
32 * int _wstat(const wchar_t*, struct _stat*)
33 * note that struct _stat != struct stat;
35 #if defined(_WIN32) && !defined(_MSC_VER) && defined(_WIN64)
40 typedef struct _stat GStatBufW64;
42 pbd_g_stat(const gchar* filename, GStatBufW64* buf)
44 gunichar2* wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
45 if (wfilename == NULL) {
50 int len = wcslen ((wchar_t*)wfilename);
51 while (len > 0 && G_IS_DIR_SEPARATOR (wfilename[len-1])) {
54 if (len > 0 && (!g_path_is_absolute (filename) || len > g_path_skip_root (filename) - filename)) {
55 wfilename[len] = '\0';
58 int retval = _wstat ((wchar_t*)wfilename, buf);
59 int save_errno = errno;
64 # define GStatBuf GStatBufW64
65 # define g_stat pbd_g_stat
66 # define g_lstat pbd_g_stat
69 #endif /* __pbd_gstdio_compat_h__ */