summaryrefslogtreecommitdiff
path: root/lib/strsep.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/strsep.c')
-rw-r--r--lib/strsep.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/strsep.c b/lib/strsep.c
new file mode 100644
index 00000000..f8e55b53
--- /dev/null
+++ b/lib/strsep.c
@@ -0,0 +1,26 @@
+#include <stdio.h>
+
+char *strsep(char **stringp, const char *delim)
+{
+ char *s;
+ const char *spanp;
+ int c, sc;
+ char *tok;
+
+ if ((s = *stringp) == NULL)
+ return (NULL);
+ for (tok = s;;) {
+ c = *s++;
+ spanp = delim;
+ do {
+ if ((sc = *spanp++) == c) {
+ if (c == 0)
+ s = NULL;
+ else
+ s[-1] = 0;
+ *stringp = s;
+ return (tok);
+ }
+ } while (sc != 0);
+ }
+}