summaryrefslogtreecommitdiff
path: root/lib/strtok_r.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/strtok_r.c')
-rw-r--r--lib/strtok_r.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/strtok_r.c b/lib/strtok_r.c
new file mode 100644
index 000000000..733290422
--- /dev/null
+++ b/lib/strtok_r.c
@@ -0,0 +1,43 @@
+/*
+ * written for xine project, 2004
+ *
+ * public domain replacement function for strtok_r()
+ *
+ */
+
+#include "config.h"
+
+#include <stddef.h>
+#include <string.h>
+
+char *_xine_private_strtok_r(char *s, const char *delim, char **ptrptr) {
+ char *next;
+ size_t toklen, cutlen;
+
+ /* first or next call */
+ if (s) *ptrptr = s;
+ else s = *ptrptr;
+
+ /* end of searching */
+ if (!s || s == '\0') return NULL;
+
+ /* cut the initial garbage */
+ cutlen = strspn(s, delim);
+ s = s + cutlen;
+
+ /* pointer before next token */
+ if ((toklen = strcspn(s, delim)) == 0) {
+ *ptrptr = NULL;
+ return NULL;
+ }
+ next = s + toklen;
+
+ /* cut current token */
+ *next = '\0';
+
+ /* prepare next call */
+ *ptrptr = next + 1;
+
+ /* return the token */
+ return s;
+}