Path: blob/main/contrib/libfido2/openbsd-compat/strsep.c
39507 views
/* $OpenBSD: strsep.c,v 1.6 2005/08/08 08:05:37 espie Exp $ */12/*-3* Copyright (c) 1990, 19934* The Regents of the University of California. All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14* 3. Neither the name of the University nor the names of its contributors15* may be used to endorse or promote products derived from this software16* without specific prior written permission.17*18* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND19* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE20* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE21* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE22* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL23* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS24* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)25* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY27* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF28* SUCH DAMAGE.29*/3031/* OPENBSD ORIGINAL: lib/libc/string/strsep.c */3233#include "openbsd-compat.h"3435#if !defined(HAVE_STRSEP)3637#include <string.h>38#include <stdio.h>3940/*41* Get next token from string *stringp, where tokens are possibly-empty42* strings separated by characters from delim.43*44* Writes NULs into the string at *stringp to end tokens.45* delim need not remain constant from call to call.46* On return, *stringp points past the last NUL written (if there might47* be further tokens), or is NULL (if there are definitely no more tokens).48*49* If *stringp is NULL, strsep returns NULL.50*/51char *52strsep(char **stringp, const char *delim)53{54char *s;55const char *spanp;56int c, sc;57char *tok;5859if ((s = *stringp) == NULL)60return (NULL);61for (tok = s;;) {62c = *s++;63spanp = delim;64do {65if ((sc = *spanp++) == c) {66if (c == 0)67s = NULL;68else69s[-1] = 0;70*stringp = s;71return (tok);72}73} while (sc != 0);74}75/* NOTREACHED */76}7778#endif /* !defined(HAVE_STRSEP) */798081