aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Isom <kyle@tyrfingr.is>2012-06-16 15:42:54 +0300
committerKyle Isom <kyle@tyrfingr.is>2012-06-16 15:42:54 +0300
commit009b02643695d8ba29f9378dcf6d73f40062b65b (patch)
tree7dab4963b86ec6ed6e52a49320fa37b1853a0572
parentcffedc430e00b523370f11668773abf10b89c275 (diff)
downloadsrvwd-009b02643695d8ba29f9378dcf6d73f40062b65b.tar.gz
srvwd-009b02643695d8ba29f9378dcf6d73f40062b65b.tar.bz2
srvwd-009b02643695d8ba29f9378dcf6d73f40062b65b.zip
improved relative path handling
-rw-r--r--response.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/response.c b/response.c
index 31056a9..02e9892 100644
--- a/response.c
+++ b/response.c
@@ -168,6 +168,7 @@ send_client_dirlist(int clientfd, char *path, request_type rtype)
char buf[SRVWD_CHUNKSIZE + 1];
char footer[] = "\t\t</ul>\r\n\t\t</p>\r\n\t</body>\r\n</html>";
char linktpl[] = "\t\t<li><a href=\"%s\">%s</a></li>\r\n";
+ char linkpath[SRVWD_CHUNKSIZE + 1];
DIR *dirlist;
struct dirent *entry;
size_t headerslen;
@@ -200,7 +201,12 @@ send_client_dirlist(int clientfd, char *path, request_type rtype)
while (NULL != (entry = readdir(dirlist))) {
memset(buf, 0, SRVWD_CHUNKSIZE + 1);
- snprintf(buf, SRVWD_CHUNKSIZE, linktpl, entry->d_name,
+ memset(linkpath, 0, SRVWD_CHUNKSIZE + 1);
+
+ strncpy(linkpath, entry->d_name, SRVWD_CHUNKSIZE - 1);
+ if (DT_DIR == entry->d_type)
+ strncat(linkpath, "/", 1);
+ snprintf(buf, SRVWD_CHUNKSIZE, linktpl, linkpath,
basename(entry->d_name));
buflen = strlen(buf);
write(clientfd, buf, buflen);