mirror of
https://github.com/lifegpc/c-utils.git
synced 2026-06-06 05:08:45 +08:00
18 lines
335 B
C
18 lines
335 B
C
#include "cstr_util.h"
|
|
|
|
#include <malloc.h>
|
|
#include <string.h>
|
|
|
|
int cstr_util_copy_str(char** dest, const char* str) {
|
|
if (!dest || !str) return 1;
|
|
size_t le = strlen(str);
|
|
char* temp = malloc(le + 1);
|
|
if (!temp) {
|
|
return 2;
|
|
}
|
|
memcpy(temp, str, le);
|
|
temp[le] = 0;
|
|
*dest = temp;
|
|
return 0;
|
|
}
|