Annotation of 43BSDReno/lib/libc/string/strsep.c, revision 1.1

1.1     ! root        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 <sys/stdc.h>
        !            21: #include <string.h>
        !            22: #include <stdio.h>
        !            23: 
        !            24: #if defined(LIBC_SCCS) && !defined(lint)
        !            25: static const char sccsid[] = "@(#)strsep.c     5.3 (Berkeley) 5/18/90";
        !            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: strsep(stringp, delim)
        !            41:        register char **stringp;
        !            42:        register const char *delim;
        !            43: {
        !            44:        register char *s;
        !            45:        register const char *spanp;
        !            46:        register int c, sc;
        !            47:        char *tok;
        !            48: 
        !            49:        if ((s = *stringp) == NULL)
        !            50:                return (NULL);
        !            51:        for (tok = s;;) {
        !            52:                c = *s++;
        !            53:                spanp = delim;
        !            54:                do {
        !            55:                        if ((sc = *spanp++) == c) {
        !            56:                                if (c == 0)
        !            57:                                        s = NULL;
        !            58:                                else
        !            59:                                        s[-1] = 0;
        !            60:                                *stringp = s;
        !            61:                                return (tok);
        !            62:                        }
        !            63:                } while (sc != 0);
        !            64:        }
        !            65:        /* NOTREACHED */
        !            66: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.