fixed -a
This commit is contained in:
1 parent
a29805cad2
commit
4b1c8c0de4
5 files changed
+148
-45
No files matched your search
+55
-5
@@ -1,17 +1,63 @@
|
||||
#ifndef _XOPEN_SOURCE
|
||||
#define _XOPEN_SOURCE 700
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include "sorting.h"
|
||||
#include "type_definitions.h"
|
||||
#include "arguments.h"
|
||||
#include "log.h"
|
||||
#include "stringing.h"
|
||||
|
||||
/* function prototypes */
|
||||
int comp_name_case_insensitive(
|
||||
const void* operand_a,
|
||||
const void* operand_b
|
||||
);
|
||||
int comp_name_case_sensitive(
|
||||
const void* operand_a,
|
||||
const void* operand_b
|
||||
);
|
||||
int sort_directories_first(
|
||||
directory_entry_t** const entry_table,
|
||||
int num_entries
|
||||
);
|
||||
|
||||
/* sort entries taking flags into account */
|
||||
int sort_entries(
|
||||
arguments_t* args,
|
||||
directory_entry_t **const entry_table,
|
||||
int num_entries
|
||||
)
|
||||
{
|
||||
if ( !args ) return -EINVAL;
|
||||
if ( !entry_table ) return -EINVAL;
|
||||
if ( 0 > num_entries ) return -EINVAL;
|
||||
|
||||
if ( true == args->group_directories )
|
||||
{
|
||||
sort_directories_first( entry_table, num_entries );
|
||||
}
|
||||
else
|
||||
{
|
||||
qsort(
|
||||
( void * )entry_table,
|
||||
( size_t )num_entries,
|
||||
sizeof( *entry_table ),
|
||||
comp_name_case_insensitive
|
||||
);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* compare entries case insensitive
|
||||
*/
|
||||
int compare_entries( const void* operand_a, const void* operand_b )
|
||||
int comp_name_case_insensitive( const void* operand_a, const void* operand_b )
|
||||
{
|
||||
if ( !operand_a || !operand_b )
|
||||
{
|
||||
@@ -28,7 +74,7 @@ int compare_entries( const void* operand_a, const void* operand_b )
|
||||
/*
|
||||
* compare entries case sensitive
|
||||
*/
|
||||
int compare_entries_casesensitive(
|
||||
int comp_name_case_sensitive(
|
||||
const void* operand_a,
|
||||
const void* operand_b
|
||||
)
|
||||
@@ -45,7 +91,11 @@ int compare_entries_casesensitive(
|
||||
return compare_strings( a->name, b->name, NAME_MAX, true );
|
||||
}
|
||||
|
||||
int group_directories( directory_entry_t** entry_table, int num_entries )
|
||||
/* group directories first */
|
||||
int sort_directories_first(
|
||||
directory_entry_t** const entry_table,
|
||||
int num_entries
|
||||
)
|
||||
{
|
||||
if ( !entry_table ) return -EINVAL;
|
||||
if ( 0 >= num_entries ) return -EINVAL;
|
||||
@@ -90,13 +140,13 @@ int group_directories( directory_entry_t** entry_table, int num_entries )
|
||||
( void * )directory_table,
|
||||
( size_t )directory_counter,
|
||||
sizeof( *directory_table ),
|
||||
compare_entries
|
||||
comp_name_case_insensitive
|
||||
);
|
||||
qsort(
|
||||
( void * )non_dir_table,
|
||||
( size_t )non_dir_counter,
|
||||
sizeof( *non_dir_table ),
|
||||
compare_entries
|
||||
comp_name_case_insensitive
|
||||
);
|
||||
|
||||
for ( int n = 0; n < directory_counter; n++ )
|
||||
|
||||
Reference in new issue
Block a user