string_dup.c 572 B

1234567891011121314151617181920212223242526272829303132
  1. /*
  2. * string_dup.c
  3. */
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include "private.h"
  7. /*--------------------------------------------------------- */
  8. char *lub_string_dup(const char *string)
  9. {
  10. if (!string)
  11. return NULL;
  12. return strdup(string);
  13. }
  14. /*--------------------------------------------------------- */
  15. char *lub_string_dupn(const char *string, unsigned int len)
  16. {
  17. char *res = NULL;
  18. if (!string)
  19. return res;
  20. res = malloc(len + 1);
  21. strncpy(res, string, len);
  22. res[len] = '\0';
  23. return res;
  24. }
  25. /*--------------------------------------------------------- */