[PATCH spice-gtk 01/14] compat: add strtok_r fallback

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx>

The following Spice proxy URI parsing code makes use of it, but it is
not available on Windows

Origin:
http://git.videolan.org/gitweb.cgi/vlc.git/?p=vlc.git;a=blob;f=compat/strtok_r.c
---
 configure.ac      |  2 +-
 gtk/glib-compat.c | 34 ++++++++++++++++++++++++++++++++++
 gtk/glib-compat.h |  8 ++++++++
 3 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 4dcd81c..3670863 100644
--- a/configure.ac
+++ b/configure.ac
@@ -235,7 +235,7 @@ else
         EXTERNAL_PNP_IDS="$with_pnp_ids_path"
 fi
 
-AC_CHECK_FUNCS(clearenv)
+AC_CHECK_FUNCS(clearenv strtok_r)
 
 PKG_CHECK_MODULES(GLIB2, glib-2.0 >= 2.22)
 AC_SUBST(GLIB2_CFLAGS)
diff --git a/gtk/glib-compat.c b/gtk/glib-compat.c
index 9ffadbb..5714173 100644
--- a/gtk/glib-compat.c
+++ b/gtk/glib-compat.c
@@ -1,5 +1,8 @@
 /* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
 /*
+   Copyright (C) 2012-2014 Red Hat, Inc.
+   Copyright © 1998-2009 VLC authors and VideoLAN
+
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
@@ -14,6 +17,7 @@
    License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 
+#include <string.h>
 #include "glib-compat.h"
 
 #if !GLIB_CHECK_VERSION(2,26,0)
@@ -105,3 +109,33 @@ guint64 g_get_monotonic_time(void)
     return (((gint64) tv.tv_sec) * 1000000) + tv.tv_usec;
 }
 #endif
+
+#ifndef HAVE_STRTOK_R
+G_GNUC_INTERNAL
+char *strtok_r(char *s, const char *delim, char **save_ptr)
+{
+    char *token;
+
+    if (s == NULL)
+        s = *save_ptr;
+
+    /* Scan leading delimiters. */
+    s += strspn (s, delim);
+    if (*s == '\0')
+        return NULL;
+
+    /* Find the end of the token. */
+    token = s;
+    s = strpbrk (token, delim);
+    if (s == NULL)
+        /* This token finishes the string. */
+        *save_ptr = strchr (token, '\0');
+    else
+    {
+        /* Terminate the token and make *SAVE_PTR point past it. */
+        *s = '\0';
+        *save_ptr = s + 1;
+    }
+    return token;
+}
+#endif
diff --git a/gtk/glib-compat.h b/gtk/glib-compat.h
index c30a735..62580e2 100644
--- a/gtk/glib-compat.h
+++ b/gtk/glib-compat.h
@@ -1,5 +1,8 @@
 /* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
 /*
+   Copyright (C) 2012-2014 Red Hat, Inc.
+   Copyright © 1998-2009 VLC authors and VideoLAN
+
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
@@ -18,6 +21,7 @@
 
 #include <glib-object.h>
 #include <gio/gio.h>
+#include "config.h"
 
 #if !GLIB_CHECK_VERSION(2,26,0)
 #define G_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func) G_DEFINE_BOXED_TYPE_WITH_CODE (TypeName, type_name, copy_func, free_func, {})
@@ -133,4 +137,8 @@ GType spice_main_context_get_type (void) G_GNUC_CONST;
 guint64 g_get_monotonic_time(void);
 #endif
 
+#ifndef HAVE_STRTOK_R
+char* strtok_r(char *s, const char *delim, char **save_ptr);
+#endif
+
 #endif /* GLIB_COMPAT_H */
-- 
1.8.4.2

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]