Blame win32/strsep.c

Packit a38265
/*
Packit a38265
 * Copyright (c) 2001 by Sun Microsystems, Inc.
Packit a38265
 * All rights reserved.
Packit a38265
 */
Packit a38265

Packit a38265
/*
Packit a38265
 * Copyright (c) 1990, 1993
Packit a38265
 *	The Regents of the University of California.  All rights reserved.
Packit a38265
 *
Packit a38265
 * Redistribution and use in source and binary forms, with or without
Packit a38265
 * modification, are permitted provided that the following conditions
Packit a38265
 * are met:
Packit a38265
 * 1. Redistributions of source code must retain the above copyright
Packit a38265
 *    notice, this list of conditions and the following disclaimer.
Packit a38265
 * 2. Redistributions in binary form must reproduce the above copyright
Packit a38265
 *    notice, this list of conditions and the following disclaimer in the
Packit a38265
 *    documentation and/or other materials provided with the distribution.
Packit a38265
 * 3. All advertising materials mentioning features or use of this software
Packit a38265
 *    must display the following acknowledgement:
Packit a38265
 *	This product includes software developed by the University of
Packit a38265
 *	California, Berkeley and its contributors.
Packit a38265
 * 4. Neither the name of the University nor the names of its contributors
Packit a38265
 *    may be used to endorse or promote products derived from this software
Packit a38265
 *    without specific prior written permission.
Packit a38265
 *
Packit a38265
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
Packit a38265
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit a38265
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit a38265
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
Packit a38265
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit a38265
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit a38265
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit a38265
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit a38265
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit a38265
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit a38265
 * SUCH DAMAGE.
Packit a38265
 */
Packit a38265

Packit a38265
#include <string.h>
Packit a38265
#include <stdio.h>
Packit a38265

Packit a38265
/*
Packit a38265
 * Get next token from string *stringp, where tokens are possibly-empty
Packit a38265
 * strings separated by characters from delim.
Packit a38265
 *
Packit a38265
 * Writes NULs into the string at *stringp to end tokens.
Packit a38265
 * delim need not remain constant from call to call.
Packit a38265
 * On return, *stringp points past the last NUL written (if there might
Packit a38265
 * be further tokens), or is NULL (if there are definitely no more tokens).
Packit a38265
 *
Packit a38265
 * If *stringp is NULL, strsep returns NULL.
Packit a38265
 */
Packit a38265
char *
Packit a38265
strsep(char **stringp, const char *delim)
Packit a38265
{
Packit a38265
	register char *s;
Packit a38265
	register const char *spanp;
Packit a38265
	register int c, sc;
Packit a38265
	char *tok;
Packit a38265

Packit a38265
	if ((s = *stringp) == NULL)
Packit a38265
		return (NULL);
Packit a38265
	for (tok = s; ; ) {
Packit a38265
		c = *s++;
Packit a38265
		spanp = delim;
Packit a38265
		do {
Packit a38265
			if ((sc = *spanp++) == c) {
Packit a38265
				if (c == 0)
Packit a38265
					s = NULL;
Packit a38265
				else
Packit a38265
					s[-1] = 0;
Packit a38265
				*stringp = s;
Packit a38265
				return (tok);
Packit a38265
			}
Packit a38265
		} while (sc != 0);
Packit a38265
	}
Packit a38265
	/* NOTREACHED */
Packit a38265
}