commit 89668f663da26d2a08827523876a6b2b8fa3c922
parent ffba757836dd113b7c4f858dd1bc7140eb017fc8
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Fri, 1 Jan 2021 20:47:30 -0800
Simplify cfetch()
Remove ability to specify a directory for the file to be put into.
Diffstat:
M | main.c | | | 26 | ++++---------------------- |
1 file changed, 4 insertions(+), 22 deletions(-)
diff --git a/main.c b/main.c
@@ -134,16 +134,6 @@ exists(const char *path)
}
int
-isdir(const char *path)
-{
- struct stat sb;
-
- if (stat(path, &sb) == -1 && errno == ENOENT)
- return 0;
- return S_ISDIR(sb.st_mode);
-}
-
-int
strtorange(unsigned int *r, unsigned int min, unsigned int max, const char *s)
{
char *ep;
@@ -499,28 +489,20 @@ int
cfetch(int argc, const char **argv, int i, const char **item)
{
const char *path;
- char pathbuf[MY_PATH_MAX];
if (warg(0, 1, argc, argv))
return ERROR;
- if (!argv[0])
- path = basename(item[GI_PATH]);
- else if (!isdir(argv[0]))
+ if (argv[0])
path = argv[0];
else {
path = basename(item[GI_PATH]);
- if (path != NULL) {
- snprintf(pathbuf, sizeof(pathbuf), "%s/%s", argv[0], path);
- path = pathbuf;
+ if (path == NULL) {
+ warn("Unable to get basename '%s'", item[GI_PATH]);
+ return ERROR;
}
}
- if (!path) {
- warn("Unable to get basename '%s'", item[GI_PATH]);
- return ERROR;
- }
-
if (timid_gopher(itemtoaddr(item), path))
return ERROR;
warnx("'%s%s' written to '%s'", item[GI_HOST], item[GI_PATH], path);