MPD

src/glib_compat.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003-2010 The Music Player Daemon Project
00003  * http://www.musicpd.org
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License along
00016  * with this program; if not, write to the Free Software Foundation, Inc.,
00017  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018  */
00019 
00020 /*
00021  * Compatibility with older GLib versions.  Some of this isn't
00022  * implemented properly, just "good enough" to allow users with older
00023  * operating systems to run MPD.
00024  */
00025 
00026 #ifndef MPD_GLIB_COMPAT_H
00027 #define MPD_GLIB_COMPAT_H
00028 
00029 #include <glib.h>
00030 
00031 #if !GLIB_CHECK_VERSION(2,14,0)
00032 
00033 #define g_queue_clear(q) do { g_queue_free(q); q = g_queue_new(); } while (0)
00034 
00035 static inline guint
00036 g_timeout_add_seconds(guint interval, GSourceFunc function, gpointer data)
00037 {
00038         return g_timeout_add(interval * 1000, function, data);
00039 }
00040 
00041 #endif /* !2.14 */
00042 
00043 #if !GLIB_CHECK_VERSION(2,16,0)
00044 
00045 static inline void
00046 g_propagate_prefixed_error(GError **dest_r, GError *src,
00047                            G_GNUC_UNUSED const gchar *format, ...)
00048 {
00049         g_propagate_error(dest_r, src);
00050 }
00051 
00052 static inline char *
00053 g_uri_escape_string(const char *unescaped,
00054                     G_GNUC_UNUSED const char *reserved_chars_allowed,
00055                     G_GNUC_UNUSED gboolean allow_utf8)
00056 {
00057         return g_strdup(unescaped);
00058 }
00059 
00060 #endif /* !2.16 */
00061 
00062 #if !GLIB_CHECK_VERSION(2,16,0)
00063 
00064 #include <string.h>
00065 
00066 static inline char *
00067 g_uri_parse_scheme(const char *uri)
00068 {
00069         const char *end = strstr(uri, "://");
00070         if (end == NULL)
00071                 return NULL;
00072         return g_strndup(uri, end - uri);
00073 }
00074 
00075 #endif
00076 
00077 #endif