comparison osdep/strsep.c @ 9380:edfe34c5405d

linux->osdep
author arpi
date Sun, 09 Feb 2003 20:18:23 +0000
parents linux/strsep.c@cbf0fed4d211
children 08cac43f1e38
comparison
equal deleted inserted replaced
9379:475bb1a6ef75 9380:edfe34c5405d
1 /* strsep implementation for systems that do not have it in libc */
2
3 #include <stdio.h>
4 #include <string.h>
5
6 #include "../config.h"
7
8 #ifndef HAVE_STRSEP
9 char *strsep(char **stringp, const char *delim) {
10 char *begin, *end;
11
12 begin = *stringp;
13 if(begin == NULL)
14 return NULL;
15
16 if(delim[0] == '\0' || delim[1] == '\0') {
17 char ch = delim[0];
18
19 if(ch == '\0')
20 end = NULL;
21 else {
22 if(*begin == ch)
23 end = begin;
24 else if(*begin == '\0')
25 end = NULL;
26 else
27 end = strchr(begin + 1, ch);
28 }
29 }
30 else
31 end = strpbrk(begin, delim);
32
33 if(end) {
34 *end++ = '\0';
35 *stringp = end;
36 }
37 else
38 *stringp = NULL;
39
40 return begin;
41 }
42 #endif