Ignore:
File:
1 edited

Legend:

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

    rfdf97f6 r12b29f3  
    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.