Path: blob/main/crypto/krb5/src/kadmin/dbutil/strtok.c
34907 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/*2* Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved3*4*/56/*7* Copyright (c) 1988 Regents of the University of California.8* All rights reserved.9*10* Redistribution and use in source and binary forms are permitted11* provided that: (1) source distributions retain this entire copyright12* notice and comment, and (2) distributions including binaries display13* the following acknowledgement: ``This product includes software14* developed by the University of California, Berkeley and its contributors''15* in the documentation or other materials provided with the distribution16* and in all advertising materials mentioning features or use of this17* software. Neither the name of the University nor the names of its18* contributors may be used to endorse or promote products derived19* from this software without specific prior written permission.20* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR21* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED22* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.23*/2425#include <stddef.h>26#include <string.h>27#include "nstrtok.h"2829/*30* Function: nstrtok31*32* Purpose: the same as strtok ... just different. does not deal with33* multiple tokens in row.34*35* Arguments:36* s (input) string to scan37* delim (input) list of delimiters38* <return value> string or null on error.39*40* Requires:41* nuttin42*43* Effects:44* sets last to string45*46* Modifies:47* last48*49*/5051char *52nstrtok(char *s, const char *delim)53{54const char *spanp;55int c, sc;56char *tok;57static char *last;585960if (s == NULL && (s = last) == NULL)61return (NULL);6263/*64* Skip (span) leading delimiters (s += strspn(s, delim), sort of).65*/66#ifdef OLD67cont:68c = *s++;69for (spanp = delim; (sc = *spanp++) != 0;) {70if (c == sc)71goto cont;72}7374if (c == 0) { /* no non-delimiter characters */75last = NULL;76return (NULL);77}78tok = s - 1;79#else80tok = s;81#endif8283/*84* Scan token (scan for delimiters: s += strcspn(s, delim), sort of).85* Note that delim must have one NUL; we stop if we see that, too.86*/87for (;;) {88c = *s++;89spanp = delim;90do {91if ((sc = *spanp++) == c) {92if (c == 0)93s = NULL;94else95s[-1] = 0;96last = s;97return (tok);98}99} while (sc != 0);100}101/* NOTREACHED */102}103104105