10Sstevel@tonic-gate /*- 20Sstevel@tonic-gate * See the file LICENSE for redistribution information. 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * Copyright (c) 1996, 1997 50Sstevel@tonic-gate * Sleepycat Software. All rights reserved. 60Sstevel@tonic-gate */ 70Sstevel@tonic-gate /* 80Sstevel@tonic-gate * Copyright (c) 1990, 1993 90Sstevel@tonic-gate * The Regents of the University of California. All rights reserved. 100Sstevel@tonic-gate * 110Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without 120Sstevel@tonic-gate * modification, are permitted provided that the following conditions 130Sstevel@tonic-gate * are met: 140Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright 150Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer. 160Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright 170Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the 180Sstevel@tonic-gate * documentation and/or other materials provided with the distribution. 190Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this software 200Sstevel@tonic-gate * must display the following acknowledgement: 210Sstevel@tonic-gate * This product includes software developed by the University of 220Sstevel@tonic-gate * California, Berkeley and its contributors. 230Sstevel@tonic-gate * 4. Neither the name of the University nor the names of its contributors 240Sstevel@tonic-gate * may be used to endorse or promote products derived from this software 250Sstevel@tonic-gate * without specific prior written permission. 260Sstevel@tonic-gate * 270Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 280Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 290Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 300Sstevel@tonic-gate * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 310Sstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 320Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 330Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 340Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 350Sstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 360Sstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 370Sstevel@tonic-gate * SUCH DAMAGE. 380Sstevel@tonic-gate */ 39*13093SRoger.Faulkner@Oracle.COM 400Sstevel@tonic-gate /* 41*13093SRoger.Faulkner@Oracle.COM * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. 420Sstevel@tonic-gate */ 430Sstevel@tonic-gate 440Sstevel@tonic-gate #include "config.h" 450Sstevel@tonic-gate 460Sstevel@tonic-gate #ifndef lint 470Sstevel@tonic-gate static const char sccsid[] = "@(#)strsep.c 10.1 (Sleepycat) 4/12/97"; 480Sstevel@tonic-gate #endif /* not lint */ 490Sstevel@tonic-gate 500Sstevel@tonic-gate #ifndef NO_SYSTEM_INCLUDES 510Sstevel@tonic-gate #include <string.h> 520Sstevel@tonic-gate #include <stdio.h> 530Sstevel@tonic-gate #endif 540Sstevel@tonic-gate 550Sstevel@tonic-gate /* 560Sstevel@tonic-gate * Get next token from string *stringp, where tokens are possibly-empty 570Sstevel@tonic-gate * strings separated by characters from delim. 580Sstevel@tonic-gate * 590Sstevel@tonic-gate * Writes NULs into the string at *stringp to end tokens. 600Sstevel@tonic-gate * delim need not remain constant from call to call. 610Sstevel@tonic-gate * On return, *stringp points past the last NUL written (if there might 620Sstevel@tonic-gate * be further tokens), or is NULL (if there are definitely no more tokens). 630Sstevel@tonic-gate * 640Sstevel@tonic-gate * If *stringp is NULL, strsep returns NULL. 650Sstevel@tonic-gate * 660Sstevel@tonic-gate * PUBLIC: #ifndef HAVE_STRSEP 670Sstevel@tonic-gate * PUBLIC: char *strsep __P((char **, const char *)); 680Sstevel@tonic-gate * PUBLIC: #endif 690Sstevel@tonic-gate */ 70*13093SRoger.Faulkner@Oracle.COM 71*13093SRoger.Faulkner@Oracle.COM #ifndef HAVE_STRSEP 72*13093SRoger.Faulkner@Oracle.COM 730Sstevel@tonic-gate char * 740Sstevel@tonic-gate strsep(stringp, delim) 750Sstevel@tonic-gate register char **stringp; 760Sstevel@tonic-gate register const char *delim; 770Sstevel@tonic-gate { 780Sstevel@tonic-gate register char *s; 790Sstevel@tonic-gate register const char *spanp; 800Sstevel@tonic-gate register int c, sc; 810Sstevel@tonic-gate char *tok; 820Sstevel@tonic-gate 830Sstevel@tonic-gate if ((s = *stringp) == NULL) 840Sstevel@tonic-gate return (NULL); 850Sstevel@tonic-gate for (tok = s;;) { 860Sstevel@tonic-gate c = *s++; 870Sstevel@tonic-gate spanp = delim; 880Sstevel@tonic-gate do { 890Sstevel@tonic-gate if ((sc = *spanp++) == c) { 900Sstevel@tonic-gate if (c == 0) 910Sstevel@tonic-gate s = NULL; 920Sstevel@tonic-gate else 930Sstevel@tonic-gate s[-1] = 0; 940Sstevel@tonic-gate *stringp = s; 950Sstevel@tonic-gate return (tok); 960Sstevel@tonic-gate } 970Sstevel@tonic-gate } while (sc != 0); 980Sstevel@tonic-gate } 990Sstevel@tonic-gate /* NOTREACHED */ 1000Sstevel@tonic-gate } 101*13093SRoger.Faulkner@Oracle.COM 102*13093SRoger.Faulkner@Oracle.COM #endif /* HAVE_STRSEP */ 103