Mercurial > code
comparison C/port/strsep.c @ 334:0b576ee64d45
* Create brand new hierarchy
* Rename DynLib to Dynlib
* Remove some warnings
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sun, 08 Mar 2015 14:26:33 +0100 |
parents | port/strsep.c@b1a084c030c8 |
children |
comparison
equal
deleted
inserted
replaced
333:412ca7a5e1ea | 334:0b576ee64d45 |
---|---|
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 } |