2018-03-07 10:30:40 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2018-03-26 09:39:54 +02:00
|
|
|
#include "cw.h"
|
|
|
|
|
2018-03-11 00:56:41 +01:00
|
|
|
/**
|
|
|
|
* @brief Duplicate a string
|
|
|
|
* @param s string to duplicate
|
|
|
|
* @return duplicated string, the memory acllocated has to be freed by #free.
|
2018-03-26 09:39:54 +02:00
|
|
|
* if there was an error allocating the memory, the return value is NULL.
|
2018-03-11 00:56:41 +01:00
|
|
|
*/
|
2018-03-26 09:39:54 +02:00
|
|
|
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;
|
2018-03-07 10:30:40 +01:00
|
|
|
}
|