1305347Sdes/**
2305347Sdes * strsep implementation for compatibility.
3305347Sdes *
4305347Sdes  * LICENSE
5305347Sdes  * Copyright (c) 2016, NLnet Labs
6305347Sdes  * All rights reserved.
7305347Sdes  *
8305347Sdes  * Redistribution and use in source and binary forms, with or without
9305347Sdes  * modification, are permitted provided that the following conditions are met:
10305347Sdes  * * Redistributions of source code must retain the above copyright notice,
11305347Sdes  *     this list of conditions and the following disclaimer.
12305347Sdes  * * Redistributions in binary form must reproduce the above copyright
13305347Sdes  *   notice, this list of conditions and the following disclaimer in the
14305347Sdes  *   documentation and/or other materials provided with the distribution.
15305347Sdes  * * Neither the name of NLnetLabs nor the names of its
16305347Sdes  *   contributors may be used to endorse or promote products derived from this
17305347Sdes  *   software without specific prior written permission.
18305347Sdes  *
19305347Sdes  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20305347Sdes  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21305347Sdes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22305347Sdes  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23305347Sdes  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24305347Sdes  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25305347Sdes  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26305347Sdes  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27305347Sdes  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28305347Sdes  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29305347Sdes  * POSSIBILITY OF SUCH DAMAGE.
30305347Sdes **/
31305347Sdes
32305347Sdes#include "config.h"
33305347Sdes
34305347Sdes/** see if character is in the delimiter array */
35305347Sdesstatic int
36305347Sdesin_delim(char c, const char* delim)
37305347Sdes{
38305347Sdes	const char* p;
39305347Sdes	if(!delim)
40305347Sdes		return 0;
41305347Sdes	for(p=delim; *p; p++) {
42305347Sdes		if(*p == c)
43305347Sdes			return 1;
44305347Sdes	}
45305347Sdes	return 0;
46305347Sdes}
47305347Sdes
48305347Sdeschar *strsep(char **stringp, const char *delim)
49305347Sdes{
50305347Sdes	char* s;
51305347Sdes	char* orig;
52305347Sdes	if(stringp == NULL || *stringp == NULL)
53305347Sdes		return NULL;
54305347Sdes	orig = *stringp;
55305347Sdes	s = *stringp;
56305347Sdes	while(*s && !in_delim(*s, delim))
57305347Sdes		s++;
58305347Sdes	if(*s) {
59305347Sdes		*s = 0;
60305347Sdes		*stringp = s+1;
61305347Sdes	} else {
62305347Sdes		*stringp = NULL;
63305347Sdes	}
64305347Sdes	return orig;
65305347Sdes}
66