Updated filemanager to use dynamically allocated strings

converted filename to dynamically allocated string
created cstr_helper
This commit is contained in:
Michael Tryby
2019-04-02 11:05:56 -04:00
parent 2c6d4ca74d
commit c98d13de80
7 changed files with 73 additions and 24 deletions

22
src/util/cstr_helper.c Normal file
View 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;
}