accounting for files "." and ".."
This commit is contained in:
15
sorting.c
15
sorting.c
@@ -2,6 +2,7 @@
|
||||
#include <dirent.h>
|
||||
#include <strings.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "defines.h"
|
||||
|
||||
extern unsigned int settings;
|
||||
@@ -13,6 +14,12 @@ int skip_hidden_files(const struct dirent *entry){
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
int skip_dot(const struct dirent *entry){
|
||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int sort_natural(const void *file0, const void *file1){
|
||||
unsigned char file_type0 = ((file*)file0)->file_type;
|
||||
@@ -49,8 +56,6 @@ int sort_alpha(const void *file0, const void *file1){
|
||||
int sort_random(const void *file0, const void *file1){
|
||||
unsigned char file_type0 = ((file*)file0)->file_type;
|
||||
unsigned char file_type1 = ((file*)file1)->file_type;
|
||||
char *file_name0 = ((file*)file0)->file_name;
|
||||
char *file_name1 = ((file*)file1)->file_name;
|
||||
static int seed = 0;
|
||||
static int random = 0;
|
||||
|
||||
@@ -60,9 +65,6 @@ int sort_random(const void *file0, const void *file1){
|
||||
if (random == 0) {
|
||||
random = seed;
|
||||
}
|
||||
if (strcmp(file_name0, ".") == 0 || strcmp(file_name0, "..") == 0) {
|
||||
return -1;
|
||||
}
|
||||
char weight = 0;
|
||||
if (file_type0 == FILE_TYPE_DIR || file_type0 == FILE_TYPE_SYMLINK) {
|
||||
weight |= 1;
|
||||
@@ -129,9 +131,6 @@ int sort_size(const void *file0, const void *file1){
|
||||
unsigned long file_size1 = ((file*)file1)->file_size;
|
||||
char *file_name0 = ((file*)file0)->file_name;
|
||||
char *file_name1 = ((file*)file1)->file_name;
|
||||
if (strcmp(file_name0, ".") == 0 || strcmp(file_name0, "..") == 0) {
|
||||
return -1;
|
||||
}
|
||||
if (file_type0 == file_type1) {
|
||||
if (file_size0 > file_size1) {
|
||||
return -1;
|
||||
|
Reference in New Issue
Block a user