strdup.c 153 B

1234567891011121314
  1. #include <u.h>
  2. #include <libc.h>
  3. char*
  4. strdup(char *s)
  5. {
  6. char *ns;
  7. ns = malloc(strlen(s) + 1);
  8. if(ns == 0)
  9. return 0;
  10. return strcpy(ns, s);
  11. }