tvi_def.h: sizeof(type) -> sizeof(*ptr)
[mplayer.git] / osdep / strsep.c
blobe3731418873499120282515cdc3e7867be1b3689
1 /*
2 * strsep implementation for systems that do not have it in libc
4 * This file is part of MPlayer.
6 * MPlayer is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * MPlayer is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <stdio.h>
22 #include <string.h>
24 #include "config.h"
25 #include "strsep.h"
27 char *strsep(char **stringp, const char *delim) {
28 char *begin, *end;
30 begin = *stringp;
31 if(begin == NULL)
32 return NULL;
34 if(delim[0] == '\0' || delim[1] == '\0') {
35 char ch = delim[0];
37 if(ch == '\0')
38 end = NULL;
39 else {
40 if(*begin == ch)
41 end = begin;
42 else if(*begin == '\0')
43 end = NULL;
44 else
45 end = strchr(begin + 1, ch);
48 else
49 end = strpbrk(begin, delim);
51 if(end) {
52 *end++ = '\0';
53 *stringp = end;
55 else
56 *stringp = NULL;
58 return begin;