Changeset 576845ec in mainline
- Timestamp:
- 2008-12-23T18:47:00Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e64c4b2
- Parents:
- 7a817d00
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/string.c
r7a817d00 r576845ec 1 1 /* 2 2 * Copyright (c) 2005 Martin Decky 3 * Copyright (C) 1998 by Wes Peters <wes@softweyr.com> 4 * Copyright (c) 1988, 1993 The Regents of the University of California. 3 * Copyright (c) 2008 Jiri Svoboda 5 4 * All rights reserved. 6 5 * … … 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) 517 { 518 char *spanp, *tok; 519 int c, sc; 520 521 if (s == NULL && (s = *last) == NULL) 522 return (NULL); 523 524 cont: 525 c = *s++; 526 for (spanp = (char *)delim; (sc = *spanp++) != 0;) { 527 if (c == sc) 528 goto cont; 529 } 530 531 if (c == 0) { /* no non-delimiter characters */ 532 *last = NULL; 533 return (NULL); 534 } 535 536 tok = s - 1; 537 538 for (;;) { 539 c = *s++; 540 spanp = (char *)delim; 541 do { 542 if ((sc = *spanp++) == c) { 543 if (c == 0) 544 s = NULL; 545 else 546 s[-1] = '\0'; 547 *last = s; 548 return (tok); 549 } 550 } while (sc != 0); 551 } 552 } 553 554 /* Ported from FBSD strtok.c 8.1 (Berkeley) 6/4/93 */ 555 char * strtok(char *s, const char *delim) 556 { 557 static char *last; 558 559 return (strtok_r(s, delim, &last)); 514 char *strtok(char *s, const char *delim) 515 { 516 static char *next; 517 518 return strtok_r(s, delim, &next); 519 } 520 521 char *strtok_r(char *s, const char *delim, char **next) 522 { 523 char *start, *end; 524 525 if (s == NULL) 526 s = *next; 527 528 /* Skip over leading delimiters. */ 529 while (*s && (strchr(delim, *s) != NULL)) ++s; 530 start = s; 531 532 /* Skip over token characters. */ 533 while (*s && (strchr(delim, *s) == NULL)) ++s; 534 end = s; 535 *next = (*s ? s + 1 : s); 536 537 if (start == end) { 538 return NULL; /* No more tokens. */ 539 } 540 541 /* Overwrite delimiter with NULL terminator. */ 542 *end = '\0'; 543 return start; 560 544 } 561 545
Note:
See TracChangeset
for help on using the changeset viewer.