X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuclient.git;a=blobdiff_plain;f=uclient-fetch.c;h=8dcb97b1349eedcea101c1fcae14ca280b7b89ee;hp=9672e07ecb0b447ef6ef93a1daec5dcd5e1c253a;hb=3a61c3f4a8820def50e7fbe68e31a07648102eca;hpb=43be3a3e32f9eb32358beaa3934623c664ae7c12;ds=sidebyside 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)