Subversion Repositories HelenOS

Rev

Rev 3729 | Rev 3731 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3729 Rev 3730
Line 1... Line 1...
1
/*
1
/*
2
 * Copyright (c) 2005 Martin Decky
2
 * Copyright (c) 2005 Martin Decky
3
 * Copyright (C) 1998 by Wes Peters <wes@softweyr.com>
3
 * Copyright (c) 2008 Jiri Svoboda
4
 * Copyright (c) 1988, 1993 The Regents of the University of California.
-
 
5
 * All rights reserved.
4
 * All rights reserved.
6
 *
5
 *
7
 * Redistribution and use in source and binary forms, with or without
6
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
7
 * modification, are permitted provided that the following conditions
9
 * are met:
8
 * are met:
Line 510... Line 509...
510
        return (char *) NULL;
509
        return (char *) NULL;
511
 
510
 
512
    return (char *) memcpy(ret, s1, len);
511
    return (char *) memcpy(ret, s1, len);
513
}
512
}
514
 
513
 
515
/* Ported from FBSD strtok.c 8.1 (Berkeley) 6/4/93 */
-
 
516
char * strtok_r(char *s, const char *delim, char **last)
514
char *strtok(char *s, const char *delim)
517
{
515
{
518
    char *spanp, *tok;
516
    static char *next;
519
    int c, sc;
-
 
520
 
517
 
521
    if (s == NULL && (s = *last) == NULL)
518
    return strtok_r(s, delim, &next);
522
        return (NULL);
519
}
523
 
520
 
524
cont:
-
 
525
    c = *s++;
-
 
526
    for (spanp = (char *)delim; (sc = *spanp++) != 0;) {
521
char *strtok_r(char *s, const char *delim, char **next)
527
        if (c == sc)
-
 
528
            goto cont;
-
 
529
    }
522
{
-
 
523
    char *start, *end;
530
 
524
 
531
    if (c == 0) {       /* no non-delimiter characters */
-
 
532
        *last = NULL;
525
    if (s == NULL)
533
        return (NULL);
526
        s = *next;
534
    }
-
 
535
 
527
 
-
 
528
    /* Skip over leading delimiters. */
-
 
529
    while (*s && (strchr(delim, *s) != NULL)) ++s;
536
    tok = s - 1;
530
    start = s;
537
 
531
 
538
    for (;;) {
-
 
539
        c = *s++;
-
 
540
        spanp = (char *)delim;
532
    /* Skip over token characters. */
541
        do {
-
 
542
            if ((sc = *spanp++) == c) {
533
    while (*s && (strchr(delim, *s) == NULL)) ++s;
543
                if (c == 0)
-
 
544
                    s = NULL;
-
 
545
                else
-
 
546
                    s[-1] = '\0';
-
 
547
                *last = s;
534
    end = s;
548
                return (tok);
-
 
549
            }
-
 
550
        } while (sc != 0);
535
    *next = (*s ? s + 1 : s);
551
    }
-
 
552
}
-
 
553
 
536
 
554
/* Ported from FBSD strtok.c 8.1 (Berkeley) 6/4/93 */
537
    if (start == end) {
555
char * strtok(char *s, const char *delim)
538
        return NULL;    /* No more tokens. */
556
{
539
    }
557
    static char *last;
-
 
558
 
540
 
-
 
541
    /* Overwrite delimiter with NULL terminator. */
-
 
542
    *end = '\0';
559
    return (strtok_r(s, delim, &last));
543
    return start;
560
}
544
}
561
 
545
 
562
/** @}
546
/** @}
563
 */
547
 */