diff options
Diffstat (limited to 'journal.c')
-rw-r--r-- | journal.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -7,9 +7,8 @@ #define TITLE u8"david’s journal" #define ENTRY_DIR "entries" -#define MAX_ENTRIES 1024 -static char *entries[MAX_ENTRIES]; +static char **entries; static int num_entries; static void load_entries(char *dir, size_t *max_fn_size) @@ -17,10 +16,14 @@ static void load_entries(char *dir, size_t *max_fn_size) DIR *d = opendir(dir); if (!d) exit(1); + int size = 1024; + entries = malloc(size * sizeof(*entries)); + struct dirent *de; while ((de = readdir(d))) { if (de->d_name[0] == '.') continue; - if (num_entries == MAX_ENTRIES) exit(1); + if (num_entries == size) + entries = realloc(entries, (size *= 2) * sizeof(*entries)); size_t fn_size = strlen(de->d_name) + 1; if (fn_size > *max_fn_size) @@ -92,8 +95,9 @@ int main() print_entry(path, entries[i]); free(entries[i]); } - + free(entries); free(path); + puts( "</body>\n" "</html>"); |