1127668Sbms/*- 2127668Sbms * Copyright (c) 1990, 1993 3127668Sbms * The Regents of the University of California. All rights reserved. 4127668Sbms * 5127668Sbms * Redistribution and use in source and binary forms, with or without 6127668Sbms * modification, are permitted provided that the following conditions 7127668Sbms * are met: 8127668Sbms * 1. Redistributions of source code must retain the above copyright 9127668Sbms * notice, this list of conditions and the following disclaimer. 10127668Sbms * 2. Redistributions in binary form must reproduce the above copyright 11127668Sbms * notice, this list of conditions and the following disclaimer in the 12127668Sbms * documentation and/or other materials provided with the distribution. 13127668Sbms * 3. All advertising materials mentioning features or use of this software 14127668Sbms * must display the following acknowledgement: 15127668Sbms * This product includes software developed by the University of 16127668Sbms * California, Berkeley and its contributors. 17127668Sbms * 4. Neither the name of the University nor the names of its contributors 18127668Sbms * may be used to endorse or promote products derived from this software 19127668Sbms * without specific prior written permission. 20127668Sbms * 21127668Sbms * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22127668Sbms * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23127668Sbms * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24127668Sbms * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25127668Sbms * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26127668Sbms * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27127668Sbms * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28127668Sbms * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29127668Sbms * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30127668Sbms * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31127668Sbms * SUCH DAMAGE. 32127668Sbms */ 33127668Sbms 34127668Sbms#if defined(LIBC_SCCS) && !defined(lint) 35127668Sbmsstatic const char rcsid[] = 36190207Srpaulo "@(#) $Header: /tcpdump/master/tcpdump/missing/strsep.c,v 1.3 2003-03-25 08:33:48 guy Exp $ (LBL)"; 37127668Sbms#endif /* LIBC_SCCS and not lint */ 38127668Sbms 39127668Sbms#ifdef HAVE_CONFIG_H 40127668Sbms#include <config.h> 41127668Sbms#endif 42127668Sbms 43127668Sbms#include <tcpdump-stdinc.h> 44127668Sbms 45127668Sbms#include <string.h> 46127668Sbms 47127668Sbms/* 48127668Sbms * Get next token from string *stringp, where tokens are possibly-empty 49127668Sbms * strings separated by characters from delim. 50127668Sbms * 51127668Sbms * Writes NULs into the string at *stringp to end tokens. 52127668Sbms * delim need not remain constant from call to call. 53127668Sbms * On return, *stringp points past the last NUL written (if there might 54127668Sbms * be further tokens), or is NULL (if there are definitely no more tokens). 55127668Sbms * 56127668Sbms * If *stringp is NULL, strsep returns NULL. 57127668Sbms */ 58127668Sbmschar * 59127668Sbmsstrsep(char **stringp, const char *delim) 60127668Sbms{ 61127668Sbms register char *s; 62127668Sbms register const char *spanp; 63127668Sbms register int c, sc; 64127668Sbms char *tok; 65127668Sbms 66127668Sbms if ((s = *stringp) == NULL) 67127668Sbms return (NULL); 68127668Sbms for (tok = s;;) { 69127668Sbms c = *s++; 70127668Sbms spanp = delim; 71127668Sbms do { 72127668Sbms if ((sc = *spanp++) == c) { 73127668Sbms if (c == 0) 74127668Sbms s = NULL; 75127668Sbms else 76127668Sbms s[-1] = 0; 77127668Sbms *stringp = s; 78127668Sbms return (tok); 79127668Sbms } 80127668Sbms } while (sc != 0); 81127668Sbms } 82127668Sbms /* NOTREACHED */ 83127668Sbms} 84