Index: uspace/lib/libc/generic/string.c
===================================================================
--- uspace/lib/libc/generic/string.c	(revision 7a817d004c64af10ac224ef010b5dad77a2828e8)
+++ uspace/lib/libc/generic/string.c	(revision 576845ecc6d0d33b065b60e3e3c05cbb996a56fe)
@@ -1,6 +1,5 @@
 /*
  * Copyright (c) 2005 Martin Decky
- * Copyright (C) 1998 by Wes Peters <wes@softweyr.com>
- * Copyright (c) 1988, 1993 The Regents of the University of California.
+ * Copyright (c) 2008 Jiri Svoboda
  * All rights reserved.
  *
@@ -513,49 +512,34 @@
 }
 
-/* Ported from FBSD strtok.c 8.1 (Berkeley) 6/4/93 */
-char * strtok_r(char *s, const char *delim, char **last)
-{
-	char *spanp, *tok;
-	int c, sc;
-
-	if (s == NULL && (s = *last) == NULL)
-		return (NULL);
-
-cont:
-	c = *s++;
-	for (spanp = (char *)delim; (sc = *spanp++) != 0;) {
-		if (c == sc)
-			goto cont;
-	}
-
-	if (c == 0) {		/* no non-delimiter characters */
-		*last = NULL;
-		return (NULL);
-	}
-
-	tok = s - 1;
-
-	for (;;) {
-		c = *s++;
-		spanp = (char *)delim;
-		do {
-			if ((sc = *spanp++) == c) {
-				if (c == 0)
-					s = NULL;
-				else
-					s[-1] = '\0';
-				*last = s;
-				return (tok);
-			}
-		} while (sc != 0);
-	}
-}
-
-/* Ported from FBSD strtok.c 8.1 (Berkeley) 6/4/93 */
-char * strtok(char *s, const char *delim)
-{
-	static char *last;
-
-	return (strtok_r(s, delim, &last));
+char *strtok(char *s, const char *delim)
+{
+	static char *next;
+
+	return strtok_r(s, delim, &next);
+}
+
+char *strtok_r(char *s, const char *delim, char **next)
+{
+	char *start, *end;
+
+	if (s == NULL)
+		s = *next;
+
+	/* Skip over leading delimiters. */
+	while (*s && (strchr(delim, *s) != NULL)) ++s;
+	start = s;
+
+	/* Skip over token characters. */
+	while (*s && (strchr(delim, *s) == NULL)) ++s;
+	end = s;
+	*next = (*s ? s + 1 : s);
+
+	if (start == end) {
+		return NULL;	/* No more tokens. */
+	}
+
+	/* Overwrite delimiter with NULL terminator. */
+	*end = '\0';
+	return start;
 }
 
