string_dupn.c 462 B

1234567891011121314151617181920212223
  1. /*
  2. * string_dupn.c
  3. */
  4. #include "private.h"
  5. #include <string.h>
  6. #include <stdlib.h>
  7. /*--------------------------------------------------------- */
  8. char *lub_string_dupn(const char *string, unsigned length)
  9. {
  10. char *result = NULL;
  11. if (NULL != string) {
  12. result = malloc(length + 1);
  13. if (NULL != result) {
  14. strncpy(result, string, length);
  15. result[length] = '\0';
  16. }
  17. }
  18. return result;
  19. }
  20. /*--------------------------------------------------------- */