summaryrefslogtreecommitdiff
path: root/utils/url.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2008-01-07 04:54:08 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2008-01-07 04:54:08 +0000
commit252ad5c476e075ec41a90163f3c79be279044be1 (patch)
tree22fe35735ee72c4a994168334dc849d5bff17d64 /utils/url.c
parent76416f1964c214fba408f3cdf15cf4935fec0252 (diff)
downloadnetsurf-252ad5c476e075ec41a90163f3c79be279044be1.tar.gz
netsurf-252ad5c476e075ec41a90163f3c79be279044be1.tar.bz2
Add url_leafname()
Remove spurious * from url_host_is_ip_address() svn path=/trunk/netsurf/; revision=3691
Diffstat (limited to 'utils/url.c')
-rw-r--r--utils/url.c34
1 files changed, 33 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.