diff options
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 39 |
1 files changed, 35 insertions, 4 deletions
@@ -31,6 +31,7 @@ #include <sys/stat.h> #include <limits.h> +#include <stdarg.h> #include <stdlib.h> #include <string.h> @@ -39,7 +40,6 @@ #include "mime.h" #include "str.h" #include "url.h" -#include "util.h" void file_free(struct file * file) @@ -74,7 +74,7 @@ fill_metadata(struct file * f) f->mime = MIME_BIN; /* check if it is a directory */ - path_len = url_build(path, PATH_MAX, data_dir, f->path, NULL); + path_len = path_build(path, PATH_MAX, data_dir, f->path, NULL); if (path_len == 0 || path_len >= PATH_MAX) return false; @@ -156,10 +156,41 @@ file_get_data_path(const struct file * f, char *data_path, size_t data_path_len, return 0; /* check if it is a directory */ - path_len = url_build(data_path, data_path_len, data_dir, f->path, - append, NULL); + path_len = path_build(data_path, data_path_len, data_dir, f->path, + append, NULL); if (path_len == 0 || path_len >= PATH_MAX) return 0; return path_len; } + +size_t +path_build(char *dst, size_t dst_size,...) +{ + va_list path_list; + const char *path; + size_t w_size; + + dst[0] = '\0'; + w_size = 0; + 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; + + if (path[0] == '\0') + continue; + + if (path[0] == '.' && path[1] == '\0') + continue; + + if (path[0] != '/' && w_size > 0 && dst[w_size - 1] != '/') + strlcat(dst, "/", dst_size); + + w_size = strlcat(dst, path, dst_size); + } + + va_end(path_list); + return w_size; +} |