blob: b71e9f7bf25ab34e17084b737af5ecccd2a0f85a [file] [log] [blame]
Jens Axboe00fb3c82008-05-30 22:17:45 +02001#include <stdio.h>
2
3char *strsep(char **stringp, const char *delim)
4{
Jens Axboefb9ee072008-05-30 22:33:47 +02005 char *s, *tok;
6 const char *spanp;
7 int c, sc;
Jens Axboe00fb3c82008-05-30 22:17:45 +02008
Jens Axboefb9ee072008-05-30 22:33:47 +02009 s = *stringp;
10 if (!s)
11 return NULL;
12
13 tok = s;
14 do {
15 c = *s++;
16 spanp = delim;
17 do {
18 sc = *spanp++;
19 if (sc == c) {
20 if (c == 0)
21 s = NULL;
22 else
23 s[-1] = 0;
24 *stringp = s;
25 return tok;
26 }
27 } while (sc != 0);
28 } while (1);
Jens Axboe00fb3c82008-05-30 22:17:45 +020029}