MPD  0.18~git
glib_compat.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003-2011 The Music Player Daemon Project
3  * http://www.musicpd.org
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 /*
21  * Compatibility with older GLib versions. Some of this isn't
22  * implemented properly, just "good enough" to allow users with older
23  * operating systems to run MPD.
24  */
25 
26 #ifndef MPD_GLIB_COMPAT_H
27 #define MPD_GLIB_COMPAT_H
28 
29 #include <glib.h>
30 
31 #if !GLIB_CHECK_VERSION(2,28,0)
32 
33 static inline gint64
34 g_source_get_time(GSource *source)
35 {
36  GTimeVal tv;
37  g_source_get_current_time(source, &tv);
38  return tv.tv_sec * 1000000 + tv.tv_usec;
39 }
40 
41 #endif
42 
43 #if defined(G_OS_WIN32) && defined(g_file_test)
44 
45 /* Modern GLib on Win32 likes to use UTF-8 for file names.
46 It redefines g_file_test() to be g_file_test_utf8().
47 This gives incorrect results for non-ASCII files.
48 Old g_file_test() is available for *binary compatibility*,
49 but symbol is hidden from linker, we copy-paste its definition here */
50 
51 #undef g_file_test
52 
53 static inline gboolean
54 g_file_test(const gchar *filename, GFileTest test)
55 {
56  gchar *utf8_filename = g_locale_to_utf8(filename, -1, NULL, NULL, NULL);
57  gboolean retval;
58 
59  if (utf8_filename == NULL)
60  return FALSE;
61 
62  retval = g_file_test_utf8(utf8_filename, test);
63 
64  g_free(utf8_filename);
65 
66  return retval;
67 }
68 
69 #endif
70 
71 #endif