00001 /***************************************************************************************** 00002 Copyright (c) 2002 The UbixOS Project 00003 All rights reserved. 00004 00005 Redistribution and use in source and binary forms, with or without modification, are 00006 permitted provided that the following conditions are met: 00007 00008 Redistributions of source code must retain the above copyright notice, this list of 00009 conditions, the following disclaimer and the list of authors. Redistributions in binary 00010 form must reproduce the above copyright notice, this list of conditions, the following 00011 disclaimer and the list of authors in the documentation and/or other materials provided 00012 with the distribution. Neither the name of the UbixOS Project nor the names of its 00013 contributors may be used to endorse or promote products derived from this software 00014 without specific prior written permission. 00015 00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 00017 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00018 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 00019 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00020 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00021 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00022 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 00023 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00024 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00025 00026 $Id: strtok_8c-source.html 88 2016-01-12 00:11:29Z reddawg $ 00027 00028 *****************************************************************************************/ 00029 00030 #include <lib/string.h> 00031 #include <ubixos/types.h> 00032 00033 char *strtok_r(char *s, const char *delim, char **last) { 00034 char *spanp; 00035 int c, sc; 00036 char *tok; 00037 00038 if ((s == NULL) && ((s = *last) == NULL)) { 00039 return(NULL); 00040 } 00041 00042 cont: 00043 c = *s++; 00044 for (spanp = (char *)delim; (sc = *spanp++) != 0; ) { 00045 if (c == sc) { 00046 goto cont; 00047 } 00048 } 00049 if (c == 0) { 00050 *last = NULL; 00051 return(NULL); 00052 } 00053 tok = s - 1; 00054 00055 for (;;) { 00056 c = *s++; 00057 spanp = (char *)delim; 00058 do { 00059 if ((sc = *spanp++) == c) { 00060 if (c == 0) { 00061 s = NULL; 00062 } 00063 else { 00064 char *w = s - 1; 00065 *w = '\0'; 00066 } 00067 *last = s; 00068 return(tok); 00069 } 00070 } while (sc != 0); 00071 } 00072 } 00073 00074 char *strtok(char *s, const char *delim) { 00075 static char *last; 00076 return (strtok_r(s, delim, &last)); 00077 } 00078 00079 /*** 00080 $Log: strtok_8c-source.html,v $ 00080 Revision 1.7 2006/12/15 17:47:07 reddawg 00080 Updates 00080 00081 Revision 1.1.1.1 2006/06/01 12:46:16 reddawg 00082 ubix2 00083 00084 Revision 1.2 2005/10/12 00:13:37 reddawg 00085 Removed 00086 00087 Revision 1.1.1.1 2005/09/26 17:24:13 reddawg 00088 no message 00089 00090 Revision 1.2 2004/05/19 03:46:32 reddawg 00091 A Few Quick Hacks To Make Things Work 00092 00093 Revision 1.1.1.1 2004/04/15 12:07:11 reddawg 00094 UbixOS v1.0 00095 00096 Revision 1.2 2004/04/13 16:36:33 reddawg 00097 Changed our copyright, it is all now under a BSD-Style license 00098 00099 END 00100 ***/ 00101 00102