diff --git a/configure.ac b/configure.ac index 70438d0..cf07212 100644 --- a/configure.ac +++ b/configure.ac @@ -42,6 +42,7 @@ if test "x$_gdk_tgt" = xquartz; then PKG_CHECK_MODULES(IGE_MAC, ige-mac-integration) AC_SUBST(IGE_MAC_LIBS) AC_SUBST(IGE_MAC_CFLAGS) + AC_DEFINE(G_OS_DARWIN, 1, [Platform detection macro missing in GLib]) fi GETTEXT_PACKAGE=spek diff --git a/src/spek-platform.c b/src/spek-platform.c index a9b62fa..c037706 100644 --- a/src/spek-platform.c +++ b/src/spek-platform.c @@ -24,6 +24,10 @@ #include #endif +#ifdef G_OS_DARWIN +#include +#endif + #include "spek-platform.h" void spek_platform_fix_args (gchar **argv, gint argc) { @@ -66,6 +70,27 @@ void spek_platform_show_uri (const gchar *uri) { } gchar *spek_platform_read_line (const gchar *uri) { +#ifdef G_OS_DARWIN + /* GIO doesn't work on OS X */ + CFStringRef str = NULL; + CFURLRef url = NULL; + CFDataRef data = NULL; + CFIndex length = 0; + gchar *buf = NULL; + + str = CFStringCreateWithCString (NULL, uri, kCFStringEncodingASCII); + url = CFURLCreateWithString (NULL, str, NULL); + if (CFURLCreateDataAndPropertiesFromResource (NULL, url, &data, NULL, NULL, NULL)) { + length = CFDataGetLength (data); + buf = (gchar *) g_malloc (length + 1); + CFDataGetBytes (data, CFRangeMake (0, length), (UInt8 *) buf); + buf[length] = '\0'; + CFRelease (data); + } + CFRelease (url); + CFRelease (str); + return buf; +#else gchar *line = NULL; GFile *file = NULL; GFileInputStream *file_stream = NULL; @@ -83,4 +108,5 @@ gchar *spek_platform_read_line (const gchar *uri) { } g_object_unref (file); return line; +#endif }