|
@@ -9617,10 +9617,8 @@ print_dir_entry(struct mg_connection *conn, struct de *de)
|
|
|
|
|
|
|
|
|
/* This function is called from send_directory() and used for
|
|
|
- * sorting directory entries by size, or name, or modification time.
|
|
|
- * On windows, __cdecl specification is needed in case if project is built
|
|
|
- * with __stdcall convention. qsort always requires __cdels callback. */
|
|
|
-static int WINCDECL
|
|
|
+ * sorting directory entries by size, name, or modification time. */
|
|
|
+static int
|
|
|
compare_dir_entries(const void *p1, const void *p2, void *arg)
|
|
|
{
|
|
|
const char *query_string = (const char *)(arg != NULL ? arg : "");
|
|
@@ -9632,13 +9630,15 @@ compare_dir_entries(const void *p1, const void *p2, void *arg)
|
|
|
query_string = "n";
|
|
|
}
|
|
|
|
|
|
+ /* Sort Directories vs Files */
|
|
|
if (a->file.is_directory && !b->file.is_directory) {
|
|
|
return -1; /* Always put directories on top */
|
|
|
} else if (!a->file.is_directory && b->file.is_directory) {
|
|
|
return 1; /* Always put directories on top */
|
|
|
- } else if (*query_string == 'n') {
|
|
|
- cmp_result = strcmp(a->file_name, b->file_name);
|
|
|
- } else if (*query_string == 's') {
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Sort by size or date */
|
|
|
+ if (*query_string == 's') {
|
|
|
cmp_result = (a->file.size == b->file.size)
|
|
|
? 0
|
|
|
: ((a->file.size > b->file.size) ? 1 : -1);
|
|
@@ -9650,6 +9650,15 @@ compare_dir_entries(const void *p1, const void *p2, void *arg)
|
|
|
: -1);
|
|
|
}
|
|
|
|
|
|
+ /* Sort by name:
|
|
|
+ * if (*query_string == 'n') ...
|
|
|
+ * but also sort files of same size/date by name as secondary criterion.
|
|
|
+ */
|
|
|
+ if (cmp_result == 0) {
|
|
|
+ cmp_result = strcmp(a->file_name, b->file_name);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* For descending order, invert result */
|
|
|
return (query_string[1] == 'd') ? -cmp_result : cmp_result;
|
|
|
}
|
|
|
return 0;
|