summaryrefslogtreecommitdiff
path: root/journal.c
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2021-06-17 23:50:22 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2021-06-17 23:50:22 -0700
commit196719b8f79d9e77e856ca4a11d40e9b56fd52a3 (patch)
tree3ba7fe7ce8d938f7d13422eaa0ffab29c198fdef /journal.c
parentb1e9dd9e3cc6e1c45419a3534a1657202e5b1de4 (diff)
downloadjournal-master.tar.gz
journal-master.tar.xz
remove limit on number of entriesHEADmaster
Diffstat (limited to 'journal.c')
-rw-r--r--journal.c12
1 files 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(
"</body>\n"
"</html>");