strtok_r.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (C) 2002 Manuel Novoa III
  3. * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
  4. *
  5. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  6. */
  7. #include "_string.h"
  8. #ifdef WANT_WIDE
  9. # define Wstrtok_r wcstok
  10. # define Wstrspn wcsspn
  11. # define Wstrpbrk wcspbrk
  12. #else
  13. # define Wstrtok_r strtok_r
  14. # define Wstrspn strspn
  15. # define Wstrpbrk strpbrk
  16. #endif
  17. Wchar *Wstrtok_r(Wchar * __restrict s1, const Wchar * __restrict s2,
  18. Wchar ** __restrict next_start)
  19. {
  20. register Wchar *s;
  21. register Wchar *p;
  22. #if 1
  23. if (((s = s1) != NULL) || ((s = *next_start) != NULL)) {
  24. if (*(s += Wstrspn(s, s2))) {
  25. if ((p = Wstrpbrk(s, s2)) != NULL) {
  26. *p++ = 0;
  27. }
  28. } else {
  29. p = s = NULL;
  30. }
  31. *next_start = p;
  32. }
  33. return s;
  34. #else
  35. if (!(s = s1)) {
  36. s = *next_start;
  37. }
  38. if (s && *(s += Wstrspn(s, s2))) {
  39. if (*(p = s + Wstrcspn(s, s2))) {
  40. *p++ = 0;
  41. }
  42. *next_start = p;
  43. return s;
  44. }
  45. return NULL; /* TODO: set *next_start = NULL for safety? */
  46. #endif
  47. }
  48. #ifndef WANT_WIDE
  49. libc_hidden_def(strtok_r)
  50. #endif