1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
Author: Reiner Herrmann <reiner@reiner-h.de>
Description: Sort list of files searched by S_find_cfh in readdir order
--- a/clownfish/src/CFCHierarchy.c
+++ b/clownfish/src/CFCHierarchy.c
@@ -115,6 +115,16 @@
}
}
+/* From qsort(3) */
+static int cmpstringp(const void *p1, const void *p2)
+{
+ /* The actual arguments to this function are "pointers to
+ * pointers to char", but strcmp(3) arguments are "pointers
+ * to char", hence the following cast plus dereference */
+
+ return strcmp(* (char * const *) p1, * (char * const *) p2);
+}
+
static char**
S_find_cfh(char *dir, char **cfh_list, size_t num_cfh) {
void *dirhandle = CFCUtil_opendir(dir);
@@ -152,6 +162,7 @@
}
}
+ qsort(cfh_list, num_cfh, sizeof(char*), cmpstringp);
FREEMEM(full_path);
CFCUtil_closedir(dirhandle, dir);
return cfh_list;
|