1
0
forked from aniani/gmnisrv

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

View File

@ -77,8 +77,15 @@ serve_autoindex(struct gmnisrv_client *client, const char *path)
namesz *= 2; namesz *= 2;
names = new; names = new;
} }
names[nameln++] = strdup(ent->d_name); if (S_ISDIR(st.st_mode)){
bufsz += snprintf(NULL, 0, "=> %s\n", ent->d_name); // +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; errno = 0;