From 3a61c3f4a8820def50e7fbe68e31a07648102eca Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 6 May 2014 15:03:21 +0200 Subject: add uclient_get_url_filename helper function Signed-off-by: Felix Fietkau --- uclient-fetch.c | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) (limited to 'uclient-fetch.c') 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 #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) -- cgit v1.2.1