strtok_r.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. libc_hidden_proto(wcsspn)
  10. libc_hidden_proto(wcspbrk)
  11. # define Wstrtok_r wcstok
  12. # define Wstrspn wcsspn
  13. # define Wstrpbrk wcspbrk
  14. #else
  15. /* Experimentally off - libc_hidden_proto(strtok_r) */
  16. /* Experimentally off - libc_hidden_proto(strspn) */
  17. /* Experimentally off - libc_hidden_proto(strpbrk) */
  18. # define Wstrtok_r strtok_r
  19. # define Wstrspn strspn
  20. # define Wstrpbrk strpbrk
  21. #endif
  22. Wchar *Wstrtok_r(Wchar * __restrict s1, const Wchar * __restrict s2,
  23. Wchar ** __restrict next_start)
  24. {
  25. register Wchar *s;
  26. register Wchar *p;
  27. #if 1
  28. if (((s = s1) != NULL) || ((s = *next_start) != NULL)) {
  29. if (*(s += Wstrspn(s, s2))) {
  30. if ((p = Wstrpbrk(s, s2)) != NULL) {
  31. *p++ = 0;
  32. }
  33. } else {
  34. p = s = NULL;
  35. }
  36. *next_start = p;
  37. }
  38. return s;
  39. #else
  40. if (!(s = s1)) {
  41. s = *next_start;
  42. }
  43. if (s && *(s += Wstrspn(s, s2))) {
  44. if (*(p = s + Wstrcspn(s, s2))) {
  45. *p++ = 0;
  46. }
  47. *next_start = p;
  48. return s;
  49. }
  50. return NULL; /* TODO: set *next_start = NULL for safety? */
  51. #endif
  52. }
  53. #ifndef WANT_WIDE
  54. libc_hidden_def(strtok_r)
  55. #endif