From 196719b8f79d9e77e856ca4a11d40e9b56fd52a3 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Thu, 17 Jun 2021 23:50:22 -0700 Subject: remove limit on number of entries --- journal.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/journal.c b/journal.c index 4e316dd..7c3313f 100644 --- a/journal.c +++ b/journal.c @@ -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( "\n" ""); -- cgit v1.2.3-70-g09d2