strsep.c 565 B

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