strdup.c 169 B

12345678910
  1. #include <stdlib.h>
  2. #include <string.h>
  3. char *strdup(const char *s)
  4. {
  5. size_t l = strlen(s);
  6. char *d = malloc(l+1);
  7. if (!d) return NULL;
  8. return memcpy(d, s, l+1);
  9. }