strdup.c 516 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * ngIRCd -- The Next Generation IRC Daemon
  3. *
  4. * strdup() implementation. Public domain.
  5. *
  6. * $Id: strdup.c,v 1.1 2005/04/16 09:20:53 fw Exp $
  7. */
  8. #include "portab.h"
  9. #include "imp.h"
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include <sys/types.h>
  13. #include "exp.h"
  14. #ifndef HAVE_STRDUP
  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