1 /* 2 ** Copyright 2001, Travis Geiselbrecht. All rights reserved. 3 ** Distributed under the terms of the NewOS License. 4 */ 5 /* 6 * Copyright (c) 2008 Travis Geiselbrecht 7 * 8 * Use of this source code is governed by a MIT-style 9 * license that can be found in the LICENSE file or at 10 * https://opensource.org/licenses/MIT 11 */ 12 #include <string.h> 13 #include <sys/types.h> 14 15 static char *___strtok = NULL; 16 17 char * strtok(char * s,char const * ct)18strtok(char *s, char const *ct) { 19 char *sbegin, *send; 20 21 sbegin = s ? s : ___strtok; 22 if (!sbegin) { 23 return NULL; 24 } 25 sbegin += strspn(sbegin,ct); 26 if (*sbegin == '\0') { 27 ___strtok = NULL; 28 return ( NULL ); 29 } 30 send = strpbrk( sbegin, ct); 31 if (send && *send != '\0') 32 *send++ = '\0'; 33 ___strtok = send; 34 return (sbegin); 35 } 36