MPD
glib_compat.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003-2010 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,14,0)
32 
33 #define g_queue_clear(q) do { g_queue_free(q); q = g_queue_new(); } while (0)
34 
35 static inline guint
36 g_timeout_add_seconds(guint interval, GSourceFunc function, gpointer data)
37 {
38  return g_timeout_add(interval * 1000, function, data);
39 }
40 
41 #endif /* !2.14 */
42 
43 #if !GLIB_CHECK_VERSION(2,16,0)
44 
45 static inline void
46 g_propagate_prefixed_error(GError **dest_r, GError *src,
47  G_GNUC_UNUSED const gchar *format, ...)
48 {
49  g_propagate_error(dest_r, src);
50 }
51 
52 static inline char *
53 g_uri_escape_string(const char *unescaped,
54  G_GNUC_UNUSED const char *reserved_chars_allowed,
55  G_GNUC_UNUSED gboolean allow_utf8)
56 {
57  return g_strdup(unescaped);
58 }
59 
60 #endif /* !2.16 */
61 
62 #if !GLIB_CHECK_VERSION(2,16,0)
63 
64 #include <string.h>
65 
66 static inline char *
67 g_uri_parse_scheme(const char *uri)
68 {
69  const char *end = strstr(uri, "://");
70  if (end == NULL)
71  return NULL;
72  return g_strndup(uri, end - uri);
73 }
74 
75 #endif
76 
77 #endif