Update.
This commit is contained in:
@@ -43,5 +43,26 @@ char* expand_home_directory(const char* path) {
|
||||
return strdup(path);
|
||||
}
|
||||
}
|
||||
char * read_file(const char * path) {
|
||||
char * expanded_path = expand_home_directory(path);
|
||||
FILE *file = fopen(expanded_path, "r");
|
||||
free(expanded_path);
|
||||
if (file == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
fseek(file, 0, SEEK_END);
|
||||
long size = ftell(file);
|
||||
fseek(file, 0, SEEK_SET);
|
||||
|
||||
#endif
|
||||
char *buffer = (char *)malloc(size + 1);
|
||||
size_t read = fread(buffer, 1, size, file);
|
||||
if (read == 0) {
|
||||
free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
buffer[read] = '\0';
|
||||
return buffer;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user