nsprpub/lib/libc/src/strtok.c

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "plstr.h"
     8 PR_IMPLEMENT(char *)
     9 PL_strtok_r(char *s1, const char *s2, char **lasts)
    10 {
    11     const char *sepp;
    12     int         c, sc;
    13     char       *tok;
    15     if( s1 == NULL )
    16     {
    17         if( *lasts == NULL )
    18             return NULL;
    20         s1 = *lasts;
    21     }
    23     for( ; (c = *s1) != 0; s1++ )
    24     {
    25         for( sepp = s2 ; (sc = *sepp) != 0 ; sepp++ )
    26         {
    27             if( c == sc )
    28                 break;
    29         }
    30         if( sc == 0 )
    31             break; 
    32     }
    34     if( c == 0 )
    35     {
    36         *lasts = NULL;
    37         return NULL;
    38     }
    40     tok = s1++;
    42     for( ; (c = *s1) != 0; s1++ )
    43     {
    44         for( sepp = s2; (sc = *sepp) != 0; sepp++ )
    45         {
    46             if( c == sc )
    47             {
    48                 *s1++ = '\0';
    49                 *lasts = s1;
    50                 return tok;
    51             }
    52         }
    53     }
    54     *lasts = NULL;
    55     return tok;
    56 }

mercurial