diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2008-01-07 04:54:08 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2008-01-07 04:54:08 +0000 |
commit | 252ad5c476e075ec41a90163f3c79be279044be1 (patch) | |
tree | 22fe35735ee72c4a994168334dc849d5bff17d64 | |
parent | 76416f1964c214fba408f3cdf15cf4935fec0252 (diff) | |
download | netsurf-252ad5c476e075ec41a90163f3c79be279044be1.tar.gz netsurf-252ad5c476e075ec41a90163f3c79be279044be1.tar.bz2 |
Add url_leafname()
Remove spurious * from url_host_is_ip_address()
svn path=/trunk/netsurf/; revision=3691
-rw-r--r-- | utils/url.c | 34 | ||||
-rw-r--r-- | utils/url.h | 1 |
2 files changed, 34 insertions, 1 deletions
diff --git a/utils/url.c b/utils/url.c index 56dcee712..aaf82cd62 100644 --- a/utils/url.c +++ b/utils/url.c @@ -106,7 +106,7 @@ bool url_host_is_ip_address(const char *host) { } else { n = true; } - *host++; + host++; } while (1); } @@ -692,6 +692,38 @@ url_func_result url_path(const char *url, char **result) return status; } +/** + * Extract leafname segment from an URL + * + * \param url an absolute URL + * \param result pointer to pointer to buffer to hold result + * \return URL_FUNC_OK on success + */ + +url_func_result url_leafname(const char *url, char **result) +{ + url_func_result status; + struct url_components components; + + assert(url); + + status = url_get_components(url, &components); + if (status == URL_FUNC_OK) { + if (!components.path) { + status = URL_FUNC_FAILED; + } else { + char *slash = strrchr(components.path, '/'); + + assert (slash != NULL); + + *result = strdup(slash + 1); + if (!(*result)) + status = URL_FUNC_NOMEM; + } + } + url_destroy_components(&components); + return status; +} /** * Attempt to find a nice filename for a URL. diff --git a/utils/url.h b/utils/url.h index a25f6a8aa..b35b6e376 100644 --- a/utils/url.h +++ b/utils/url.h @@ -53,6 +53,7 @@ url_func_result url_canonical_root(const char *url, char **result); url_func_result url_parent(const char *url, char **result); url_func_result url_plq(const char *url, char **result); url_func_result url_path(const char *url, char **result); +url_func_result url_leafname(const char *url, char **result); url_func_result url_compare(const char *url1, const char *url2, bool *result); |