This commit is contained in:
2025-03-16 22:46:09 +01:00
parent 48a543b56e
commit 7e10be7821
7 changed files with 107 additions and 198 deletions
+22 -1
View File
@@ -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