Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

strsep.c

Go to the documentation of this file.
00001 /*      $OpenBSD: strsep.c,v 1.3 1997/08/20 04:28:14 millert Exp $      */
00002 
00003 /*-
00004  * Copyright (c) 1990, 1993
00005  *      The Regents of the University of California.  All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  * 1. Redistributions of source code must retain the above copyright
00011  *    notice, this list of conditions and the following disclaimer.
00012  * 2. Redistributions in binary form must reproduce the above copyright
00013  *    notice, this list of conditions and the following disclaimer in the
00014  *    documentation and/or other materials provided with the distribution.
00015  * 3. All advertising materials mentioning features or use of this software
00016  *    must display the following acknowledgement:
00017  *      This product includes software developed by the University of
00018  *      California, Berkeley and its contributors.
00019  * 4. Neither the name of the University nor the names of its contributors
00020  *    may be used to endorse or promote products derived from this software
00021  *    without specific prior written permission.
00022  *
00023  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00024  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00027  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00028  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00029  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00032  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00033  * SUCH DAMAGE.
00034  */
00035 
00036 #include <string.h>
00037 #include <stdio.h>
00038 
00039 #if defined(LIBC_SCCS) && !defined(lint)
00040 #if 0
00041 static char sccsid[] = "@(#)strsep.c    8.1 (Berkeley) 6/4/93";
00042 #else
00043 static char *rcsid = "$OpenBSD: strsep.c,v 1.3 1997/08/20 04:28:14 millert Exp $";
00044 #endif
00045 #endif /* LIBC_SCCS and not lint */
00046 
00047 /*
00048  * Get next token from string *stringp, where tokens are possibly-empty
00049  * strings separated by characters from delim.  
00050  *
00051  * Writes NULs into the string at *stringp to end tokens.
00052  * delim need not remain constant from call to call.
00053  * On return, *stringp points past the last NUL written (if there might
00054  * be further tokens), or is NULL (if there are definitely no more tokens).
00055  *
00056  * If *stringp is NULL, strsep returns NULL.
00057  */
00058 char *
00059 strsep(stringp, delim)
00060         register char **stringp;
00061         register const char *delim;
00062 {
00063         register char *s;
00064         register const char *spanp;
00065         register int c, sc;
00066         char *tok;
00067 
00068         if ((s = *stringp) == NULL)
00069                 return (NULL);
00070         for (tok = s;;) {
00071                 c = *s++;
00072                 spanp = delim;
00073                 do {
00074                         if ((sc = *spanp++) == c) {
00075                                 if (c == 0)
00076                                         s = NULL;
00077                                 else
00078                                         s[-1] = 0;
00079                                 *stringp = s;
00080                                 return (tok);
00081                         }
00082                 } while (sc != 0);
00083         }
00084         /* NOTREACHED */
00085 }

Generated on Sun May 14 14:51:12 2006 by  doxygen 1.4.2