strdup.c 189 B

123456789101112131415
  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. setmalloctag(ns, getcallerpc(&s));
  11. return strcpy(ns, s);
  12. }