diff --git a/src/gmnlm.c b/src/gmnlm.c
index b4f20de66d50fe9f0287c74b9a9292fe8ddd48d3..0546486340b7299be3c97266dd534a1354bf31a3 100644
--- a/src/gmnlm.c
+++ b/src/gmnlm.c
@@ -188,6 +188,15 @@ {
char *path_fmt = get_data_pathfmt();
static char path[PATH_MAX+1];
snprintf(path, sizeof(path), path_fmt, "bookmarks.gmi");
+ if (mkdirs(dirname(path), 0755) != 0) {
+ snprintf(path, sizeof(path), path_fmt, "bookmarks.gmi");
+ free(path_fmt);
+ fprintf(stderr, "Error creating directory %s: %s\n",
+ dirname(path), strerror(errno));
+ return;
+ }
+
+ snprintf(path, sizeof(path), path_fmt, "bookmarks.gmi");
free(path_fmt);
struct stat buf;