avoid using g_stat on windows if glib < 2.26

Closes #452.
This commit is contained in:
derselbst 2019-02-03 16:35:19 +01:00
parent 12dd1c7653
commit b6a5c5f570
2 changed files with 12 additions and 8 deletions

View file

@ -457,6 +457,10 @@ else(NOT enable-pkgconfig)
# Mandatory libraries: glib and gthread
pkg_check_modules ( GLIB REQUIRED glib-2.0>=2.6.5 gthread-2.0>=2.6.5 )
if ( GLIB_VERSION VERSION_LESS "2.26" )
message ( WARNING "Your version of glib is very old. This may cause problems with fluidsynth's sample cache on Windows. Consider updating to glib 2.26 or newer!" )
endif ( GLIB_VERSION VERSION_LESS "2.26" )
include ( UnsetPkgConfig )
# Optional features

View file

@ -374,24 +374,24 @@ fluid_istream_t fluid_socket_get_istream(fluid_socket_t sock);
fluid_ostream_t fluid_socket_get_ostream(fluid_socket_t sock);
/* File access */
#define fluid_stat(_filename, _statbuf) g_stat((_filename), (_statbuf))
#if !GLIB_CHECK_VERSION(2, 26, 0)
/* GStatBuf has not been introduced yet, manually typedef to what they had at that time:
* https://github.com/GNOME/glib/blob/e7763678b56e3be073cc55d707a6e92fc2055ee0/glib/gstdio.h#L98-L115
*/
#if defined(WIN32) || HAVE_WINDOWS_H // somehow reliably mock G_OS_WIN32??
#if defined (_MSC_VER) && !defined(_WIN64)
typedef struct _stat32 fluid_stat_buf_t;
#else
typedef struct _stat fluid_stat_buf_t;
#endif
// Any effort from our side to reliably mock GStatBuf on Windows is in vain. E.g. glib-2.16 is broken as it uses struct stat rather than struct _stat32 on Win x86.
// Disable it (the user has been warned by cmake).
#undef fluid_stat
#define fluid_stat(_filename, _statbuf) (-1)
typedef struct _fluid_stat_buf_t{int st_mtime;} fluid_stat_buf_t;
#else
/* posix, OS/2, etc. */
typedef struct stat fluid_stat_buf_t;
/* posix, OS/2, etc. */
typedef struct stat fluid_stat_buf_t;
#endif
#else
typedef GStatBuf fluid_stat_buf_t;
#endif
#define fluid_stat(_filename, _statbuf) g_stat((_filename), (_statbuf))
#define fluid_file_test g_file_test