forked from aniani/gmnisrv
1
0
Fork 0

autoindex: end directories with trailing slash

This commit is contained in:
Zach DeCook 2020-12-22 23:23:15 -05:00 committed by Drew DeVault
parent 61bf4c53aa
commit eac874b925
1 changed files with 9 additions and 2 deletions

View File

@ -77,8 +77,15 @@ serve_autoindex(struct gmnisrv_client *client, const char *path)
namesz *= 2;
names = new;
}
names[nameln++] = strdup(ent->d_name);
bufsz += snprintf(NULL, 0, "=> %s\n", ent->d_name);
if (S_ISDIR(st.st_mode)){
// +1 for trailing slash, +1 for \0
names[nameln] = malloc(strlen(ent->d_name)+1+1);
sprintf(names[nameln], "%s/", ent->d_name);
} else {
names[nameln] = strdup(ent->d_name);
}
bufsz += snprintf(NULL, 0, "=> %s\n", names[nameln]);
nameln++;
}
errno = 0;