You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
418 B

#include <string.h>
#include <stdlib.h>
#include "cw.h"
* @brief Duplicate a string
* @param s string to duplicate
* @return duplicated string, the memory acllocated has to be freed by #free.
* if there was an error allocating the memory, the return value is NULL.
char *cw_strdup(const char *s)
size_t size = strlen(s) + 1;
char *p = malloc(size);
if (p != NULL)
memcpy(p, s, size);
return p;