dupstr.c 300 B

1234567891011121314151617181920
  1. /*
  2. * Allocate a duplicate of an ordinary C NUL-terminated string.
  3. */
  4. #include <string.h>
  5. #include "defs.h"
  6. #include "misc.h"
  7. char *dupstr(const char *s)
  8. {
  9. char *p = NULL;
  10. if (s) {
  11. int len = strlen(s);
  12. p = snewn(len + 1, char);
  13. strcpy(p, s);
  14. }
  15. return p;
  16. }