gmni

a gemini line mode client
git clone https://git.clttr.info/gmni.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

commit 77b73efbcd3ea7ed9e3e4c0aa19d9247e21d3c87
parent 93f30522f032c0d8137ba3ebe140b4019842d13d
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Tue, 16 Mar 2021 00:07:27 -0400

all: use posix_dirname rather than dirname

Diffstat:
Msrc/gmnlm.c | 19++++++-------------
Msrc/tofu.c | 13++++---------
2 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/src/gmnlm.c b/src/gmnlm.c @@ -162,18 +162,15 @@ save_bookmark(struct browser *browser) size_t n; n = snprintf(path, sizeof(path), path_fmt, "bookmarks.gmi"); + free(path_fmt); assert(n < sizeof(path)); - strncpy(dname, dirname(path), sizeof(dname)-1); + posix_dirname(path, dname); if (mkdirs(dname, 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)); + dname, strerror(errno)); return; } - snprintf(path, sizeof(path), path_fmt, "bookmarks.gmi"); - free(path_fmt); FILE *f = fopen(path, "a"); if (!f) { fprintf(stderr, "Error opening %s for writing: %s\n", @@ -203,19 +200,15 @@ open_bookmarks(struct browser *browser) size_t n; n = snprintf(path, sizeof(path), path_fmt, "bookmarks.gmi"); + free(path_fmt); assert(n < sizeof(path)); - strncpy(dname, dirname(path), sizeof(dname)-1); + posix_dirname(path, dname); if (mkdirs(dname, 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)); + dname, strerror(errno)); return; } - snprintf(path, sizeof(path), path_fmt, "bookmarks.gmi"); - free(path_fmt); - struct stat buf; if (stat(path, &buf) == -1 && errno == ENOENT) { // TOCTOU, but we almost certainly don't care diff --git a/src/tofu.c b/src/tofu.c @@ -177,21 +177,16 @@ gemini_tofu_init(struct gemini_tofu *tofu, tofu_callback_t *cb, void *cb_data) n = snprintf(tofu->known_hosts_path, sizeof(tofu->known_hosts_path), path_fmt, "known_hosts"); + free(path_fmt); assert(n < sizeof(tofu->known_hosts_path)); - strncpy(dname, dirname(tofu->known_hosts_path), sizeof(dname)-1); + posix_dirname(tofu->known_hosts_path, dname); if (mkdirs(dname, 0755) != 0) { - snprintf(tofu->known_hosts_path, sizeof(tofu->known_hosts_path), - path_fmt, "known_hosts"); - fprintf(stderr, "Error creating directory %s: %s\n", - dirname(tofu->known_hosts_path), strerror(errno)); + fprintf(stderr, "Error creating directory %s: %s\n", dname, + strerror(errno)); return; } - snprintf(tofu->known_hosts_path, sizeof(tofu->known_hosts_path), - path_fmt, "known_hosts"); - free(path_fmt); - tofu->callback = cb; tofu->cb_data = cb_data;