strsep.c 726 B

12345678910111213141516171819202122232425262728293031323334353637
  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 __USE_BSD
  9. /* Experimentally off - libc_hidden_proto(strpbrk) */
  10. /* Experimentally off - libc_hidden_proto(strcspn) */
  11. /* Experimentally off - libc_hidden_proto(strsep) */
  12. char *strsep(char ** __restrict s1, const char * __restrict s2)
  13. {
  14. register char *s = *s1;
  15. register char *p;
  16. #if 1
  17. p = NULL;
  18. if (s && *s && (p = strpbrk(s, s2))) {
  19. *p++ = 0;
  20. }
  21. #else
  22. if (s && *s && *(p = s + strcspn(s, s2))) {
  23. *p++ = 0;
  24. } else {
  25. p = NULL;
  26. }
  27. #endif
  28. *s1 = p;
  29. return s;
  30. }
  31. libc_hidden_def(strsep)
  32. #endif