1*42252Smarc /*- 2*42252Smarc * Copyright (c) 1990 The Regents of the University of California. 335538Sbostic * All rights reserved. 435538Sbostic * 5*42252Smarc * %sccs.include.redist.c% 635538Sbostic */ 735538Sbostic 8*42252Smarc #include <sys/stdc.h> 9*42252Smarc #include <string.h> 10*42252Smarc #include <stdio.h> 11*42252Smarc 1235538Sbostic #if defined(LIBC_SCCS) && !defined(lint) 13*42252Smarc static const char sccsid[] = "@(#)strsep.c 5.3 (Berkeley) 05/18/90"; 1435538Sbostic #endif /* LIBC_SCCS and not lint */ 1535538Sbostic 16*42252Smarc /* 17*42252Smarc * Get next token from string *stringp, where tokens are nonempty 18*42252Smarc * strings separated by characters from delim. 19*42252Smarc * 20*42252Smarc * Writes NULs into the string at *stringp to end tokens. 21*42252Smarc * delim need not remain constant from call to call. 22*42252Smarc * On return, *stringp points past the last NUL written (if there might 23*42252Smarc * be further tokens), or is NULL (if there are definitely no more tokens). 24*42252Smarc * 25*42252Smarc * If *stringp is NULL, strtoken returns NULL. 26*42252Smarc */ 2735538Sbostic char * 28*42252Smarc strsep(stringp, delim) 29*42252Smarc register char **stringp; 30*42252Smarc register const char *delim; 3135538Sbostic { 32*42252Smarc register char *s; 33*42252Smarc register const char *spanp; 3435538Sbostic register int c, sc; 3535538Sbostic char *tok; 3635538Sbostic 37*42252Smarc if ((s = *stringp) == NULL) 38*42252Smarc return (NULL); 39*42252Smarc for (tok = s;;) { 40*42252Smarc c = *s++; 4135538Sbostic spanp = delim; 4235538Sbostic do { 4335538Sbostic if ((sc = *spanp++) == c) { 44*42252Smarc if (c == 0) 45*42252Smarc s = NULL; 46*42252Smarc else 47*42252Smarc s[-1] = 0; 48*42252Smarc *stringp = s; 49*42252Smarc return (tok); 5035538Sbostic } 51*42252Smarc } while (sc != 0); 5235538Sbostic } 5335538Sbostic /* NOTREACHED */ 5435538Sbostic } 55