diff options
author | wrmr | 2025-06-23 15:10:10 -0400 |
---|---|---|
committer | wrmr | 2025-06-23 15:10:10 -0400 |
commit | 26ea24c56d21f70ec37344c9b8e851658efbfbb8 (patch) | |
tree | abefd958bf57ff37f91cfa7c1e469f9445437f44 | |
parent | 9f5945f567d29488041b872321cf6a1cf7580c8b (diff) |
ensure $HOME/.bink exists on startup
-rw-r--r-- | main.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/main.c b/main.c index dec4ff2..c5d17c2 100644 --- a/main.c +++ b/main.c @@ -23,6 +23,8 @@ #include <curses.h> #include <stdarg.h> #include <linux/limits.h> /* PATH_MAX */ +#include <sys/stat.h> /* mkdir(2) */ +#include <errno.h> #include <time.h> #include <regex.h> #include <err.h> @@ -383,6 +385,13 @@ void edit_post(Post *post, Arena *temp) { system(cstr_fmt(temp, "%s %s", get_editor(), post->path)); } +void ensure_dotbink_exists(Arena *temp) { + const char *binkdir = cstr_fmt(temp, "/home/%s/.bink", getlogin()); + if (mkdir(binkdir, 0775) && errno != EEXIST) { + err(1, "couldn't create %s", binkdir); + } +} + void new_post(Arena *temp) { struct timespec ts; if (clock_gettime(CLOCK_REALTIME, &ts)) { @@ -423,8 +432,6 @@ void new_post(Arena *temp) { /* this will probably crash if there are zero posts */ int main(void) { - init_curses(); - /* init */ Arena post_arena = { 0 }; @@ -434,6 +441,8 @@ int main(void) { arena_reserve(&post_arena, 128 << 10L); arena_reserve(&gfx_arena, 128 << 10L); + ensure_dotbink_exists(&temp_arena); + PostList posts = { 0 }; Gfx gfx = { 0 }; @@ -441,6 +450,8 @@ int main(void) { "([ \t\n]+|^)[@~]?%s([: \t\n]|$)", getlogin()), REG_EXTENDED | REG_ICASE | REG_NOSUB); + init_curses(); + posts_refresh(&posts, &post_arena); gfx_load(&gfx, &posts, &gfx_arena); |