Updated filemanager to use dynamically allocated strings
converted filename to dynamically allocated string created cstr_helper
This commit is contained in:
22
src/util/cstr_helper.c
Normal file
22
src/util/cstr_helper.c
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
int copy_cstr(const char *source, char **destination, size_t *size)
|
||||
// Determines length, allocates memory, and returns a null terminated copy
|
||||
// Be Aware: caller is responsible for freeing memory
|
||||
{
|
||||
size_t len;
|
||||
|
||||
len = strlen(source);
|
||||
*destination = (char *) calloc(len + 1, sizeof(char));
|
||||
|
||||
if (*destination == NULL)
|
||||
return -1;
|
||||
else {
|
||||
strncpy(*destination, source, len);
|
||||
*size = len + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user