summaryrefslogtreecommitdiff
path: root/uclient-fetch.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2014-05-06 15:03:21 +0200
committerFelix Fietkau <nbd@openwrt.org>2014-05-06 15:03:21 +0200
commit3a61c3f4a8820def50e7fbe68e31a07648102eca (patch)
treec0a27a3c04214e5da17f1bc357892ff8651cd202 /uclient-fetch.c
parent43be3a3e32f9eb32358beaa3934623c664ae7c12 (diff)
downloaduclient-3a61c3f4a8820def50e7fbe68e31a07648102eca.tar.gz
add uclient_get_url_filename helper function
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Diffstat (limited to 'uclient-fetch.c')
-rw-r--r--uclient-fetch.c28
1 files changed, 6 insertions, 22 deletions
diff --git a/uclient-fetch.c b/uclient-fetch.c
index 9672e07..8dcb97b 100644
--- a/uclient-fetch.c
+++ b/uclient-fetch.c
@@ -25,6 +25,7 @@
#include <libubox/blobmsg.h>
#include "uclient.h"
+#include "uclient-utils.h"
#ifdef __APPLE__
#define LIB_EXT "dylib"
@@ -42,10 +43,9 @@ static int error_ret;
static int open_output_file(const char *path, bool create)
{
- const char *str;
char *filename;
- int len;
int flags = O_WRONLY;
+ int ret;
if (create)
flags |= O_CREAT;
@@ -61,27 +61,11 @@ static int open_output_file(const char *path, bool create)
if (create)
flags |= O_EXCL;
- len = strcspn(path, ";&");
- while (len > 0 && path[len - 1] == '/')
- len--;
-
- for (str = path + len - 1; str >= path; str--) {
- if (*str == '/')
- break;
- }
-
- str++;
- len -= str - path;
-
- if (len > 0) {
- filename = alloca(len + 1);
- strncpy(filename, str, len);
- filename[len] = 0;
- } else {
- filename = "index.html";
- }
+ filename = uclient_get_url_filename(path, "index.html");
+ ret = open(filename, flags, 0644);
+ free(filename);
- return open(filename, flags, 0644);
+ return ret;
}
static void request_done(struct uclient *cl)