strtok_r.c 1.1 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 Wstrtok_r wcstok
  11. # define Wstrspn __wcsspn
  12. # define Wstrpbrk __wcspbrk
  13. #else
  14. # define __Wstrtok_r __strtok_r
  15. # define Wstrtok_r strtok_r
  16. # define Wstrspn __strspn
  17. # define Wstrpbrk __strpbrk
  18. #endif
  19. Wchar attribute_hidden *__Wstrtok_r(Wchar * __restrict s1, const Wchar * __restrict s2,
  20. Wchar ** __restrict next_start)
  21. {
  22. register Wchar *s;
  23. register Wchar *p;
  24. #if 1
  25. if (((s = s1) != NULL) || ((s = *next_start) != NULL)) {
  26. if (*(s += Wstrspn(s, s2))) {
  27. if ((p = Wstrpbrk(s, s2)) != NULL) {
  28. *p++ = 0;
  29. }
  30. } else {
  31. p = s = NULL;
  32. }
  33. *next_start = p;
  34. }
  35. return s;
  36. #else
  37. if (!(s = s1)) {
  38. s = *next_start;
  39. }
  40. if (s && *(s += Wstrspn(s, s2))) {
  41. if (*(p = s + Wstrcspn(s, s2))) {
  42. *p++ = 0;
  43. }
  44. *next_start = p;
  45. return s;
  46. }
  47. return NULL; /* TODO: set *next_start = NULL for safety? */
  48. #endif
  49. }
  50. strong_alias(__Wstrtok_r,Wstrtok_r)