strdup.c 475 B

123456789101112131415161718192021222324252627282930313233343536
  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 "imp.h"
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include <sys/types.h>
  14. #include "exp.h"
  15. GLOBAL char *
  16. strdup( const char *s )
  17. {
  18. char *dup;
  19. size_t len = strlen( s );
  20. size_t alloc = len + 1;
  21. if (len >= alloc ) return NULL;
  22. dup = malloc( alloc );
  23. if (dup) strlcpy(dup, s, alloc );
  24. return dup;
  25. }
  26. #endif