1139823Simp#include "config.h" 21541Srgrimes 31541Srgrimes#if HAVE_STRSEP 41541Srgrimes 51541Srgrimesint dummy; 61541Srgrimes 71541Srgrimes#else 81541Srgrimes 91541Srgrimes/* Id: compat_strsep.c,v 1.4 2014/12/11 09:05:01 schwarze Exp */ 101541Srgrimes/* $OpenBSD: strsep.c,v 1.7 2014/02/05 20:42:32 stsp Exp $ */ 111541Srgrimes 121541Srgrimes/*- 131541Srgrimes * Copyright (c) 1990, 1993 141541Srgrimes * The Regents of the University of California. All rights reserved. 151541Srgrimes * 161541Srgrimes * Redistribution and use in source and binary forms, with or without 171541Srgrimes * modification, are permitted provided that the following conditions 181541Srgrimes * are met: 191541Srgrimes * 1. Redistributions of source code must retain the above copyright 201541Srgrimes * notice, this list of conditions and the following disclaimer. 211541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 221541Srgrimes * notice, this list of conditions and the following disclaimer in the 231541Srgrimes * documentation and/or other materials provided with the distribution. 241541Srgrimes * 3. Neither the name of the University nor the names of its contributors 251541Srgrimes * may be used to endorse or promote products derived from this software 261541Srgrimes * without specific prior written permission. 271541Srgrimes * 281541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 291541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 3050477Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 311541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 321541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 331541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 341541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 351541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 361541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 371541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 381541Srgrimes * SUCH DAMAGE. 3932350Seivind */ 40101090Srwatson 41142215Sglebius/* 4232350Seivind * Get next token from string *stringp, where tokens are possibly-empty 431541Srgrimes * strings separated by characters from delim. 4412693Sphk * 4544078Sdfr * Writes NULs into the string at *stringp to end tokens. 4612693Sphk * delim need not remain constant from call to call. 471541Srgrimes * On return, *stringp points past the last NUL written (if there might 4812693Sphk * be further tokens), or is NULL (if there are definitely no more tokens). 491541Srgrimes * 5018892Sbde * If *stringp is NULL, strsep returns NULL. 511541Srgrimes */ 521541Srgrimeschar * 531541Srgrimesstrsep(char **stringp, const char *delim) 541541Srgrimes{ 5544165Sjulian char *s; 561541Srgrimes const char *spanp; 578426Swollman int c, sc; 5858313Slile char *tok; 5971963Sjulian 601541Srgrimes if ((s = *stringp) == NULL) 611541Srgrimes return (NULL); 621541Srgrimes for (tok = s;;) { 631541Srgrimes c = *s++; 641541Srgrimes spanp = delim; 6584931Sfjoe do { 6644627Sjulian if ((sc = *spanp++) == c) { 6744627Sjulian if (c == 0) 68142215Sglebius s = NULL; 69142215Sglebius else 70142215Sglebius s[-1] = 0; 71142215Sglebius *stringp = s; 72163606Srwatson return (tok); 73163606Srwatson } 741541Srgrimes } while (sc != 0); 751541Srgrimes } 761541Srgrimes /* NOTREACHED */ 7744078Sdfr} 7812942Swollman 791541Srgrimes#endif 8012693Sphk