strtok.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2007, 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 https://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  ***************************************************************************/
00022 
00023 #include "curl_setup.h"
00024 
00025 #ifndef HAVE_STRTOK_R
00026 #include <stddef.h>
00027 
00028 #include "strtok.h"
00029 
00030 char *
00031 Curl_strtok_r(char *ptr, const char *sep, char **end)
00032 {
00033   if(!ptr)
00034     /* we got NULL input so then we get our last position instead */
00035     ptr = *end;
00036 
00037   /* pass all letters that are including in the separator string */
00038   while(*ptr && strchr(sep, *ptr))
00039     ++ptr;
00040 
00041   if(*ptr) {
00042     /* so this is where the next piece of string starts */
00043     char *start = ptr;
00044 
00045     /* set the end pointer to the first byte after the start */
00046     *end = start + 1;
00047 
00048     /* scan through the string to find where it ends, it ends on a
00049        null byte or a character that exists in the separator string */
00050     while(**end && !strchr(sep, **end))
00051       ++*end;
00052 
00053     if(**end) {
00054       /* the end is not a null byte */
00055       **end = '\0';  /* zero terminate it! */
00056       ++*end;        /* advance the last pointer to beyond the null byte */
00057     }
00058 
00059     return start; /* return the position where the string starts */
00060   }
00061 
00062   /* we ended up on a null byte, there are no more strings to find! */
00063   return NULL;
00064 }
00065 
00066 #endif /* this was only compiled if strtok_r wasn't present */


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:06