summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--browse.c6
-rw-r--r--download.c4
-rw-r--r--url.c9
-rw-r--r--url.h5
4 files changed, 11 insertions, 13 deletions
diff --git a/browse.c b/browse.c
index 7526853..a129eb6 100644
--- a/browse.c
+++ b/browse.c
@@ -49,7 +49,8 @@ build_browse_url(struct kreq * r, char *url, size_t url_size, const char *file)
char *page_name;
page_name = strlen(r->pagename) == 0 ? BROWSE_URL : r->pagename;
- return url_build(url, url_size, 4, r->pname, page_name, r->path, file);
+ return url_build(url, url_size, r->pname, page_name, r->path, file,
+ NULL);
}
void
@@ -67,7 +68,8 @@ browse(struct kreq * r)
http_exit(r, KHTTP_400, "browse: Invalid request path");
/* list requested directory content */
- url_size = url_build(current_dir, URL_LENGTH_MAX, 2, DATA_DIR, r->path);
+ url_size = url_build(current_dir, URL_LENGTH_MAX, DATA_DIR, r->path,
+ NULL);
if (url_size == 0)
http_exit(r, KHTTP_404, "browse: Unable to build data path");
if (url_size >= URL_LENGTH_MAX)
diff --git a/download.c b/download.c
index ba59b68..ce22ea7 100644
--- a/download.c
+++ b/download.c
@@ -54,8 +54,8 @@ download(struct kreq * r)
http_exit(r, KHTTP_400, "download: Invalid request path");
/* build requested file path */
- path_size = url_build(file_path, URL_LENGTH_MAX, 2, DATA_DIR,
- "File.txt");
+ path_size = url_build(file_path, URL_LENGTH_MAX, DATA_DIR, "File.txt",
+ NULL);
if (path_size == 0)
http_exit(r, KHTTP_404, "download: Unable to build file path");
if (path_size >= URL_LENGTH_MAX)
diff --git a/url.c b/url.c
index 3e71289..6ed2c19 100644
--- a/url.c
+++ b/url.c
@@ -51,7 +51,7 @@ check_request_path(char *path)
}
size_t
-url_build(char *dst, size_t dst_size, int count,...)
+url_build(char *dst, size_t dst_size,...)
{
va_list path_list;
const char *path;
@@ -60,15 +60,12 @@ url_build(char *dst, size_t dst_size, int count,...)
dst[0] = '\0';
w_size = 0;
- va_start(path_list, count);
- for (path_index = 0; path_index < count; path_index++) {
+ va_start(path_list, dst_size);
+ while ((path = va_arg(path_list, char *)) != NULL) {
/* no more space in dst buffer */
if (w_size >= dst_size)
break;
- path = va_arg(path_list, char *);
-
- assert(path != NULL);
if (path[0] == '\0')
continue;
diff --git a/url.h b/url.h
index b4552a7..f4c5e2d 100644
--- a/url.h
+++ b/url.h
@@ -49,13 +49,12 @@ check_request_path(char *);
* The first argument is the destination buffer where the URL will be written.
* It is required.
* The second argument is the size of the destination buffer. It is required.
- * The third argument is the number of URL components provided in the following
- * vargs.
+ * The remaining arguments are the url parts
* Returns the number of characters written to the destination buffer. If it
* is equal to the destination buffer size, it means the buffer was too small
* and the resulting URL has been truncated.
*/
size_t
-url_build(char *, size_t, int,...);
+url_build(char *, size_t,...);
#endif /* URL_H */