Jens Axboe | 00fb3c8 | 2008-05-30 22:17:45 +0200 | [diff] [blame] | 1 | #include <stdio.h> |
2 | |||||
3 | char *strsep(char **stringp, const char *delim) | ||||
4 | { | ||||
Jens Axboe | fb9ee07 | 2008-05-30 22:33:47 +0200 | [diff] [blame] | 5 | char *s, *tok; |
6 | const char *spanp; | ||||
7 | int c, sc; | ||||
Jens Axboe | 00fb3c8 | 2008-05-30 22:17:45 +0200 | [diff] [blame] | 8 | |
Jens Axboe | fb9ee07 | 2008-05-30 22:33:47 +0200 | [diff] [blame] | 9 | 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 Axboe | 00fb3c8 | 2008-05-30 22:17:45 +0200 | [diff] [blame] | 29 | } |