home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Networking / wu-ftpd-2.4.2b13-MIHS / support / arpa / strsep.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-03  |  2.1 KB  |  72 lines

  1. /*-
  2.  * Copyright (c) 1990 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that: (1) source distributions retain this entire copyright
  7.  * notice and comment, and (2) distributions including binaries display
  8.  * the following acknowledgement:  ``This product includes software
  9.  * developed by the University of California, Berkeley and its contributors''
  10.  * in the documentation or other materials provided with the distribution
  11.  * and in all advertising materials mentioning features or use of this
  12.  * software. Neither the name of the University nor the names of its
  13.  * contributors may be used to endorse or promote products derived
  14.  * from this software without specific prior written permission.
  15.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  16.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  17.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  18.  */
  19.  
  20. #include <string.h>
  21. #include <stdio.h>
  22.  
  23. #if defined(LIBC_SCCS) && !defined(lint)
  24. static const char sccsid[] = "@(#)strsep.c    5.3 (Berkeley) 5/18/90";
  25.  
  26. #endif /* LIBC_SCCS and not lint */
  27.  
  28. /*
  29.  * Get next token from string *stringp, where tokens are nonempty
  30.  * strings separated by characters from delim.
  31.  *
  32.  * Writes NULs into the string at *stringp to end tokens.
  33.  * delim need not remain constant from call to call.
  34.  * On return, *stringp points past the last NUL written (if there might
  35.  * be further tokens), or is NULL (if there are definitely no more tokens).
  36.  *
  37.  * If *stringp is NULL, strtoken returns NULL.
  38.  */
  39. char *
  40. #ifdef __STDC__
  41. strsep(register char **stringp, register char *delim)
  42. #else
  43. strsep(stringp,delim)
  44. register char **stringp;
  45. register char *delim;
  46. #endif
  47. {
  48.     register char *s;
  49.     register char *spanp;
  50.     register int c,
  51.       sc;
  52.     char *tok;
  53.  
  54.     if ((s = *stringp) == NULL)
  55.         return (NULL);
  56.     for (tok = s;;) {
  57.         c = *s++;
  58.         spanp = delim;
  59.         do {
  60.             if ((sc = *spanp++) == c) {
  61.                 if (c == 0)
  62.                     s = NULL;
  63.                 else
  64.                     s[-1] = 0;
  65.                 *stringp = s;
  66.                 return (tok);
  67.             }
  68.         } while (sc != 0);
  69.     }
  70.     /* NOTREACHED */
  71. }
  72.