Changeset 15d0046 in mainline for uspace/lib/posix/source/string.c


Ignore:
Timestamp:
2014-09-12T13:22:33Z (10 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9b20126
Parents:
8db09e4 (diff), 105d8d6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/source/string.c

    r8db09e4 r15d0046  
    508508       
    509509        return NULL;
     510}
     511
     512/** Split string by delimiters.
     513 *
     514 * @param s             String to be tokenized. May not be NULL.
     515 * @param delim         String with the delimiters.
     516 * @return              Pointer to the prefix of @a s before the first
     517 *                      delimiter character. NULL if no such prefix
     518 *                      exists.
     519 */
     520char *posix_strtok(char *s, const char *delim)
     521{
     522        static char *next;
     523
     524        return posix_strtok_r(s, delim, &next);
     525}
     526
     527
     528/** Split string by delimiters.
     529 *
     530 * @param s             String to be tokenized. May not be NULL.
     531 * @param delim         String with the delimiters.
     532 * @param next          Variable which will receive the pointer to the
     533 *                      continuation of the string following the first
     534 *                      occurrence of any of the delimiter characters.
     535 *                      May be NULL.
     536 * @return              Pointer to the prefix of @a s before the first
     537 *                      delimiter character. NULL if no such prefix
     538 *                      exists.
     539 */
     540char *posix_strtok_r(char *s, const char *delim, char **next)
     541{
     542        char *start, *end;
     543
     544        if (s == NULL)
     545                s = *next;
     546
     547        /* Skip over leading delimiters. */
     548        while (*s && (posix_strchr(delim, *s) != NULL)) ++s;
     549        start = s;
     550
     551        /* Skip over token characters. */
     552        while (*s && (posix_strchr(delim, *s) == NULL)) ++s;
     553        end = s;
     554        *next = (*s ? s + 1 : s);
     555
     556        if (start == end) {
     557                return NULL;    /* No more tokens. */
     558        }
     559
     560        /* Overwrite delimiter with NULL terminator. */
     561        *end = '\0';
     562        return start;
    510563}
    511564
Note: See TracChangeset for help on using the changeset viewer.