synced with 1.1036
[mplayer/greg.git] / osdep / strsep.c
blob51e16c359984cbc43720f81e028e3eb499b44dd6
1 /* strsep implementation for systems that do not have it in libc */
3 #include <stdio.h>
4 #include <string.h>
6 #include "config.h"
8 #ifndef HAVE_STRSEP
9 char *strsep(char **stringp, const char *delim) {
10 char *begin, *end;
12 begin = *stringp;
13 if(begin == NULL)
14 return NULL;
16 if(delim[0] == '\0' || delim[1] == '\0') {
17 char ch = delim[0];
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);
30 else
31 end = strpbrk(begin, delim);
33 if(end) {
34 *end++ = '\0';
35 *stringp = end;
37 else
38 *stringp = NULL;
40 return begin;
42 #endif