strtok_r.c 491 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * ngIRCd -- The Next Generation IRC Daemon
  3. */
  4. #include "portab.h"
  5. /**
  6. * @file
  7. * Implementation of strtok_r()
  8. */
  9. #ifndef HAVE_STRTOK_R
  10. #include <string.h>
  11. char *
  12. strtok_r(char *str, const char *delim, char **saveptr)
  13. {
  14. char *tmp;
  15. if (!str)
  16. str = *saveptr;
  17. str += strspn(str, delim);
  18. if (*str == 0)
  19. return NULL;
  20. tmp = str + strcspn(str, delim); /* get end of token */
  21. if (*tmp) { /* another delimiter */
  22. *tmp = 0;
  23. tmp++;
  24. }
  25. *saveptr = tmp;
  26. return str;
  27. }
  28. #endif