summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--main.c15
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);