Reformatted

FossilOrigin-Name: 4e99b5c4df0169dc245e94f880fc771b028bf0226aa639cc5077f0062de5cb9c
This commit is contained in:
7u83@mail.ru 2018-03-26 07:39:54 +00:00
parent 4cedc04193
commit 4718bcf3bb
1 changed files with 10 additions and 6 deletions

View File

@ -1,15 +1,19 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include "cw.h"
/** /**
* @brief Duplicate a string * @brief Duplicate a string
* @param s string to duplicate * @param s string to duplicate
* @return duplicated string, the memory acllocated has to be freed by #free. * @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) { char *cw_strdup(const char *s)
size_t size = strlen(s) + 1; {
char *p = malloc(size); size_t size = strlen(s) + 1;
if (p) char *p = malloc(size);
memcpy(p, s, size); if (p != NULL)
return p; memcpy(p, s, size);
return p;
} }