comparison port/strsep.c @ 486:7ee8da32da98

Unify all in modules/
author David Demelier <markand@malikania.fr>
date Fri, 13 Nov 2015 09:26:46 +0100
parents
children
comparison
equal deleted inserted replaced
485:898d8b29a4f1 486:7ee8da32da98
1 /*
2 * strsep.c -- separate a string by delimiters
3 *
4 * Copyright (c) 2011, 2012, David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #include <stdlib.h>
20 #include <string.h>
21
22 char *
23 strsep(char **stringp, const char *delim)
24 {
25 char *item, *ptr;
26
27 if (*stringp == NULL || delim[0] == '\0')
28 return NULL;
29
30 item = *stringp;
31 if ((ptr = strpbrk(*stringp, delim)) == NULL) {
32 *stringp = NULL;
33 return item;
34 }
35
36 *ptr = '\0';
37 *stringp = ptr + 1;
38
39 return item;
40 }