[Spice-devel] [usbredir v2 PATCH] usbredirfilter: Win32: implement strtok_r to be used by windows (win_strtok_r)
Uri Lublin
uril at redhat.com
Thu May 24 07:40:26 PDT 2012
mingw imlpements neigther strtok_r nor strtok_s.
So here is a simple implementation of strtok_r (for windows).
It assumes the delimiter is a single character, which is
good enough for usbredirfilter.
---
usbredirparser/usbredirfilter.c | 47 +++++++++++++++++++++++++++++++++++++++
1 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/usbredirparser/usbredirfilter.c b/usbredirparser/usbredirfilter.c
index b74c921..df48acb 100644
--- a/usbredirparser/usbredirfilter.c
+++ b/usbredirparser/usbredirfilter.c
@@ -23,6 +23,53 @@
#include <string.h>
#include <errno.h>
+#ifdef WIN32
+#define strtok_r win_strtok_r
+
+/*
+ * strtok_r like implementation for windows (mingw).
+ *
+ * Only the first character of delim is used as a delimiter
+ */
+char *win_strtok_r(char *str, const char *delim, char **state)
+{
+ const char d = delim[0];
+ char *p;
+ int found = 0;
+
+ /* sanity checks */
+ if ((delim == NULL) || (state == NULL))
+ return NULL;
+
+ if (str == NULL) {
+ str = *state;
+ }
+
+ if (str == NULL) {
+ return NULL;
+ }
+
+ for (p=str; *p ; p++) {
+ if (*p == d) {
+ found = 1;
+ *p++ = '\0';
+ while (*p && *p==d) /* skip all delimiters */
+ p++;
+ break;
+ }
+ }
+
+ *state = found ? p : NULL;
+
+ /* do not return empty strings */
+ if (!*str)
+ return NULL;
+
+ return str;
+}
+
+#endif
+
#include "usbredirfilter.h"
int usbredirfilter_string_to_rules(
--
1.7.1
More information about the Spice-devel
mailing list