2016-12-10 15:32:03 +01:00
|
|
|
#include "fsdir.h"
|
2016-11-15 23:06:01 +01:00
|
|
|
|
|
|
|
void DirEntryCpy(DirEntry* dest, const DirEntry* orig) {
|
|
|
|
memcpy(dest, orig, sizeof(DirEntry));
|
2018-10-01 23:51:05 +02:00
|
|
|
dest->name = dest->path + dest->p_name;
|
2016-11-15 23:06:01 +01:00
|
|
|
}
|
|
|
|
|
2018-09-13 17:47:48 +09:00
|
|
|
int compDirEntry(const void* e1, const void* e2) {
|
|
|
|
const DirEntry* entry1 = (const DirEntry*) e1;
|
|
|
|
const DirEntry* entry2 = (const DirEntry*) e2;
|
|
|
|
if (entry1->type == T_DOTDOT) return -1;
|
|
|
|
if (entry2->type == T_DOTDOT) return 1;
|
|
|
|
if (entry1->type != entry2->type)
|
|
|
|
return entry1->type - entry2->type;
|
|
|
|
return strncasecmp(entry1->path, entry2->path, 256);
|
|
|
|
}
|
|
|
|
|
2016-11-15 23:06:01 +01:00
|
|
|
void SortDirStruct(DirStruct* contents) {
|
2018-09-13 17:47:48 +09:00
|
|
|
qsort(contents->entry, contents->n_entries, sizeof(DirEntry), compDirEntry);
|
2018-09-18 01:30:10 +02:00
|
|
|
// fix entry->names after qsort
|
2018-09-13 17:47:48 +09:00
|
|
|
for (int i = 0; i < (int)contents->n_entries; i++) {
|
|
|
|
DirEntry* entry = &(contents->entry[i]);
|
2018-10-01 23:51:05 +02:00
|
|
|
entry->name = entry->path + entry->p_name;
|
2016-11-15 23:06:01 +01:00
|
|
|
}
|
|
|
|
}
|