strdup.c 437 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * ngIRCd -- The Next Generation IRC Daemon
  3. */
  4. #include "portab.h"
  5. /**
  6. * @file
  7. * strdup() implementation. Public domain.
  8. */
  9. #ifndef HAVE_STRDUP
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include <sys/types.h>
  13. GLOBAL char *
  14. strdup(const char *s)
  15. {
  16. char *dup;
  17. size_t len = strlen(s);
  18. size_t alloc = len + 1;
  19. if (len >= alloc)
  20. return NULL;
  21. dup = malloc(alloc);
  22. if (dup)
  23. strlcpy(dup, s, alloc );
  24. return dup;
  25. }
  26. #endif