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