mirror of
https://git.sr.ht/~sircmpwn/gmni
synced 2024-05-07 05:16:03 +02:00
all: use posix_dirname rather than dirname
This commit is contained in:
parent
93f30522f0
commit
77b73efbcd
19
src/gmnlm.c
19
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
|
||||
|
|
13
src/tofu.c
13
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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue