00001 /*************************************************************************** 00002 * _ _ ____ _ 00003 * Project ___| | | | _ \| | 00004 * / __| | | | |_) | | 00005 * | (__| |_| | _ <| |___ 00006 * \___|\___/|_| \_\_____| 00007 * 00008 * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al. 00009 * 00010 * This software is licensed as described in the file COPYING, which 00011 * you should have received as part of this distribution. The terms 00012 * are also available at http://curl.haxx.se/docs/copyright.html. 00013 * 00014 * You may opt to use, copy, modify, merge, publish, distribute and/or sell 00015 * copies of the Software, and permit persons to whom the Software is 00016 * furnished to do so, under the terms of the COPYING file. 00017 * 00018 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 00019 * KIND, either express or implied. 00020 * 00021 * $Id: strtok.c,v 1.13 2004/01/29 13:56:45 bagder Exp $ 00022 ***************************************************************************/ 00023 00024 #include "setup.h" 00025 00026 #ifndef HAVE_STRTOK_R 00027 #include <stddef.h> 00028 #include <string.h> 00029 00030 #include "strtok.h" 00031 00032 char * 00033 Curl_strtok_r(char *ptr, const char *sep, char **end) 00034 { 00035 if (!ptr) 00036 /* we got NULL input so then we get our last position instead */ 00037 ptr = *end; 00038 00039 /* pass all letters that are including in the separator string */ 00040 while (*ptr && strchr(sep, *ptr)) 00041 ++ptr; 00042 00043 if (*ptr) { 00044 /* so this is where the next piece of string starts */ 00045 char *start = ptr; 00046 00047 /* set the end pointer to the first byte after the start */ 00048 *end = start + 1; 00049 00050 /* scan through the string to find where it ends, it ends on a 00051 null byte or a character that exists in the separator string */ 00052 while (**end && !strchr(sep, **end)) 00053 ++*end; 00054 00055 if (**end) { 00056 /* the end is not a null byte */ 00057 **end = '\0'; /* zero terminate it! */ 00058 ++*end; /* advance the last pointer to beyond the null byte */ 00059 } 00060 00061 return start; /* return the position where the string starts */ 00062 } 00063 00064 /* we ended up on a null byte, there are no more strings to find! */ 00065 return NULL; 00066 } 00067 00068 #endif /* this was only compiled if strtok_r wasn't present */
1.5.6