blob: ead535a07e04336e2fb8280b78be653865b9a89c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
// The strdup() function shall return a pointer to a new string, which is a
// duplicate of the string pointed to by s. The returned pointer can be passed
// to free(). A null pointer is returned if the new string cannot be created.
char *strdup(const char *s) {
size_t l = strlen(s);
char *r = malloc(l + 1);
if (!r) {
return NULL;
}
strcpy(r, s);
return r;
}
|