diff options
author | Uri Lublin <uril@redhat.com> | 2012-05-14 13:05:28 +0300 |
---|---|---|
committer | Uri Lublin <uril@redhat.com> | 2012-07-08 22:55:19 +0300 |
commit | 8db9136a14b78db713a564647e6e676e5fcb8a9b (patch) | |
tree | 65ecee8ff115d7d5e87dc2a190351b54dc0606e7 | |
parent | cb74b3113076d6e18c799a0c73978e1aea32bad0 (diff) |
usbredirfilter: Win32: use strtok_r implementation of glibc
I could not find an imlpementation of strtok_r in mingw.
It seems strtok_s requires an additional package to be installed on the
usb-host machine.
This patch adds the glibc implementation of strtok_r to be used on windows.
-rw-r--r-- | usbredirparser/Makefile.am | 4 | ||||
-rw-r--r-- | usbredirparser/strtok_r.c | 65 | ||||
-rw-r--r-- | usbredirparser/strtok_r.h | 26 | ||||
-rw-r--r-- | usbredirparser/usbredirfilter.c | 5 |
4 files changed, 100 insertions, 0 deletions
diff --git a/usbredirparser/Makefile.am b/usbredirparser/Makefile.am index d73ba77..53c1012 100644 --- a/usbredirparser/Makefile.am +++ b/usbredirparser/Makefile.am @@ -6,5 +6,9 @@ libusbredirparser_la_HEADERS = usbredirparser.h usbredirfilter.h usbredirproto.h libusbredirparser_la_LDFLAGS = -version-info $(LIBUSBREDIRPARSER_SO_VERSION) \ -no-undefined +if OS_WIN32 +libusbredirparser_la_SOURCES += strtok_r.c strtok_r.h +endif + pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libusbredirparser.pc diff --git a/usbredirparser/strtok_r.c b/usbredirparser/strtok_r.c new file mode 100644 index 0000000..227d1ea --- /dev/null +++ b/usbredirparser/strtok_r.c @@ -0,0 +1,65 @@ +/* Reentrant string tokenizer. Generic version. + Copyright (C) 1991,1996-1999,2001,2004 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C 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 + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <string.h> + +/* Parse S into tokens separated by characters in DELIM. + If S is NULL, the saved pointer in SAVE_PTR is used as + the next starting point. For example: + char s[] = "-abc-=-def"; + char *sp; + x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def" + x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL + x = strtok_r(NULL, "=", &sp); // x = NULL + // s = "abc\0-def\0" +*/ +char * +glibc_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') + { + *save_ptr = s; + 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; +} diff --git a/usbredirparser/strtok_r.h b/usbredirparser/strtok_r.h new file mode 100644 index 0000000..50e6e0e --- /dev/null +++ b/usbredirparser/strtok_r.h @@ -0,0 +1,26 @@ +/* Reentrant string tokenizer. Generic version. + Copyright (C) 1991,1996-1999,2001,2004 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C 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 + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _USBREDIRPARSER_STRTOK_H_ +#define _USBREDIRPARSER_STRTOK_H_ + +char * +glibc_strtok_r(char *s, const char *delim, char **save_ptr); + +#endif diff --git a/usbredirparser/usbredirfilter.c b/usbredirparser/usbredirfilter.c index b74c921..b90d16f 100644 --- a/usbredirparser/usbredirfilter.c +++ b/usbredirparser/usbredirfilter.c @@ -23,6 +23,11 @@ #include <string.h> #include <errno.h> +#ifdef WIN32 +#include "strtok_r.h" +#define strtok_r glibc_strtok_r +#endif + #include "usbredirfilter.h" int usbredirfilter_string_to_rules( |