Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.3 KiB

  1. #define NULL 0
  2. #pragma warning(disable:4057)
  3. /* reentrant strtok, copied/pasted from crt */
  4. char * __cdecl strtok_r (
  5. char * string,
  6. const char * control,
  7. char ** nextoken
  8. )
  9. {
  10. unsigned char *str;
  11. const unsigned char *ctrl = control;
  12. unsigned char map[32];
  13. int count;
  14. /* Clear control map */
  15. for (count = 0; count < 32; count++)
  16. map[count] = 0;
  17. /* Set bits in delimiter table */
  18. do {
  19. map[*ctrl >> 3] |= (1 << (*ctrl & 7));
  20. } while (*ctrl++);
  21. /* Initialize str. If string is NULL, set str to the saved
  22. * pointer (i.e., continue breaking tokens out of the string
  23. * from the last strtok call) */
  24. if (string)
  25. str = string;
  26. else
  27. str = *nextoken;
  28. /* Find beginning of token (skip over leading delimiters). Note that
  29. * there is no token iff this loop sets str to point to the terminal
  30. * null (*str == '\0') */
  31. while ( (map[*str >> 3] & (1 << (*str & 7))) && *str )
  32. str++;
  33. string = str;
  34. /* Find the end of the token. If it is not the end of the string,
  35. * put a null there. */
  36. for ( ; *str ; str++ )
  37. if ( map[*str >> 3] & (1 << (*str & 7)) ) {
  38. *str++ = '\0';
  39. break;
  40. }
  41. /* Update nextoken */
  42. *nextoken = str;
  43. /* Determine if a token has been found. */
  44. if ( string == str )
  45. return NULL;
  46. else
  47. return string;
  48. }