diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2021-06-17 23:50:22 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2021-06-17 23:50:22 -0700 |
commit | 196719b8f79d9e77e856ca4a11d40e9b56fd52a3 (patch) | |
tree | 3ba7fe7ce8d938f7d13422eaa0ffab29c198fdef | |
parent | b1e9dd9e3cc6e1c45419a3534a1657202e5b1de4 (diff) | |
download | journal-196719b8f79d9e77e856ca4a11d40e9b56fd52a3.tar.gz journal-196719b8f79d9e77e856ca4a11d40e9b56fd52a3.tar.xz |
-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>"); |