SortDirStruct workaround for T_DOTDOT and T_ROOT

This commit is contained in:
d0k3 2018-09-18 01:30:10 +02:00
parent 9c4ff77476
commit 2d807915e6
2 changed files with 7 additions and 5 deletions

View File

@ -17,13 +17,15 @@ int compDirEntry(const void* e1, const void* e2) {
void SortDirStruct(DirStruct* contents) {
qsort(contents->entry, contents->n_entries, sizeof(DirEntry), compDirEntry);
// fix entry->names after qsort
for (int i = 0; i < (int)contents->n_entries; i++) {
DirEntry* entry = &(contents->entry[i]);
if (entry->type == T_DOTDOT) {
entry->name = entry->path + 8;
} else {
if ((entry->type == T_DIR) || (entry->type == T_FILE)) {
char* slash = strrchr(entry->path, '/');
entry->name = slash ? slash + 1 : entry->path;
} else {
// somewhat hacky, applies to T_DOTDOT and T_ROOT (see fsdrive.c)
entry->name = entry->path + 4;
}
}
}

View File

@ -179,8 +179,8 @@ void SearchDirContents(DirStruct* contents, const char* path, const char* patter
contents->n_entries = 0; // not required, but so what?
} else {
// create virtual '..' entry
contents->entry->name = contents->entry->path + 8;
strncpy(contents->entry->path, "*?*?*", 8);
contents->entry->name = contents->entry->path + 4;
strncpy(contents->entry->path, "*?*", 4);
strncpy(contents->entry->name, "..", 4);
contents->entry->type = T_DOTDOT;
contents->entry->size = 0;