Thumbnail

rani/cscroll.git

Clone URL: https://git.buni.party/rani/cscroll.git

commit 424363212668e68a098f45d86feee72c1d544149 Author: Raniconduh <clagv.randomgames@gmail.com> Date: Sun Dec 12 10:59:22 2021 +0000 sorted directories first, then alphabetically diff --git a/src/dir.c b/src/dir.c index f7f7c02..eedc979 100644 --- a/src/dir.c +++ b/src/dir.c @@ -216 +2120 @@ bool show_dot_files = false;  bool permission_denied = false;     +static int cmp(const void * a, const void * b) { + const struct dir_entry_t * c = *(const struct dir_entry_t **)a; + const struct dir_entry_t * d = *(const struct dir_entry_t **)b; + + // sort directories first + if (c->file_type == FILE_DIR && d->file_type != FILE_DIR) + return -1; + else if (d->file_type == FILE_DIR && c->file_type != FILE_DIR) + return 1; + else + return strcmp(c->name, d->name); +} + +  int list_dir(char * dir_path) {   struct dirent * d_entry;   DIR * dir = opendir(dir_path); @@ -1216 +1358 @@ int list_dir(char * dir_path) {     closedir(dir);   + qsort(dir_entries, n_dir_entries, sizeof(struct dir_entry_t*), cmp); +   return 0;  }