commit c7592c6a5c2ff7b390af89f297d5c9e1c34c9414
parent eb2873b2ebe1f436d8fb4cd7c336889ad0ddddfd
Author: Eyal Sawady <ecs@d2evs.net>
Date: Mon, 21 Sep 2020 00:09:47 -0400
save_bookmark: fix bookmark file creation
Diffstat:
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/gmnlm.c b/src/gmnlm.c
@@ -1,6 +1,7 @@
#include <assert.h>
#include <ctype.h>
#include <getopt.h>
+#include <libgen.h>
#include <limits.h>
#include <openssl/bio.h>
#include <openssl/err.h>
@@ -127,8 +128,14 @@ save_bookmark(struct browser *browser)
const char *path_fmt = get_data_pathfmt();
static char path[PATH_MAX+1];
snprintf(path, sizeof(path), path_fmt, "bookmarks.gmi");
- mkdirs(path, 0755);
+ if (mkdirs(dirname(path), 0755) != 0) {
+ snprintf(path, sizeof(path), path_fmt, "bookmarks.gmi");
+ fprintf(stderr, "Error creating directory %s: %s\n",
+ dirname(path), strerror(errno));
+ return;
+ }
+ snprintf(path, sizeof(path), path_fmt, "bookmarks.gmi");
FILE *f = fopen(path, "a");
if (!f) {
fprintf(stderr, "Error opening %s for writing: %s\n",