mirror of
https://github.com/lifegpc/c-utils.git
synced 2026-07-08 01:30:39 +08:00
Initialize
This commit is contained in:
17
cstr_util.c
Normal file
17
cstr_util.c
Normal file
@@ -0,0 +1,17 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user