diff options
author | Felix Fietkau <nbd@openwrt.org> | 2014-05-06 15:03:21 +0200 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2014-05-06 15:03:21 +0200 |
commit | 3a61c3f4a8820def50e7fbe68e31a07648102eca (patch) | |
tree | c0a27a3c04214e5da17f1bc357892ff8651cd202 /uclient-utils.c | |
parent | 43be3a3e32f9eb32358beaa3934623c664ae7c12 (diff) | |
download | uclient-3a61c3f4a8820def50e7fbe68e31a07648102eca.tar.gz |
add uclient_get_url_filename helper function
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Diffstat (limited to 'uclient-utils.c')
-rw-r--r-- | uclient-utils.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/uclient-utils.c b/uclient-utils.c index 93a6880..a375eea 100644 --- a/uclient-utils.c +++ b/uclient-utils.c @@ -160,3 +160,25 @@ void http_digest_calculate_response(char *dest, const struct http_digest_data *d http_create_hash(dest, h_a2_strings, ARRAY_SIZE(h_a2_strings)); http_create_hash(dest, resp_strings, ARRAY_SIZE(resp_strings)); } + +char *uclient_get_url_filename(const char *url, const char *default_name) +{ + const char *str; + int len = strcspn(url, ";&"); + + while (len > 0 && url[len - 1] == '/') + len--; + + for (str = url + len - 1; str >= url; str--) { + if (*str == '/') + break; + } + + str++; + len -= str - url; + + if (len > 0) + return strncpy(calloc(1, len + 1), str, len); + + return strdup(default_name); +} |