aboutsummaryrefslogtreecommitdiffstats
path: root/src/tree.c
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2021-02-26 16:16:13 +0000
committerJoursoir <chat@joursoir.net>2021-02-26 16:16:13 +0000
commit3aabad59dc2bbdb74777f2d0dc195fb0bbe75bfc (patch)
tree7c340979b1f3466b4b78f3c03ac5fd311d617d92 /src/tree.c
parenta8fe7bce0ea33f71485cf8c2e4c8330831c849ce (diff)
downloadlock-password-3aabad59dc2bbdb74777f2d0dc195fb0bbe75bfc.tar.gz
lock-password-3aabad59dc2bbdb74777f2d0dc195fb0bbe75bfc.tar.bz2
lock-password-3aabad59dc2bbdb74777f2d0dc195fb0bbe75bfc.zip
improve code and codestyle; mv/rm cmd don't use global vars anymore
Diffstat (limited to 'src/tree.c')
-rw-r--r--src/tree.c41
1 files changed, 2 insertions, 39 deletions
diff --git a/src/tree.c b/src/tree.c
index 387ef8b..1a746b2 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -7,6 +7,7 @@
#include "tree.h"
#include "xstd.h"
+#include "easydir.h"
#define ANSIC_RST "\x1B[0m"
#define ANSIC_BBLU "\x1B[34;1m"
@@ -28,40 +29,6 @@ static void entries_sort(char **entries, const int size)
}
}
-static int is_dir(const char *path)
-{
- struct stat buffer;
- if(stat(path, &buffer))
- return 0;
- return S_ISDIR(buffer.st_mode);
-}
-
-static int count_dir_entries(const char *path)
-{
- int counter = 0;
- DIR *dir;
- struct dirent *dir_entry;
-
- dir = opendir(path);
- if(dir == NULL) {
- fprintf(stderr, "opendir() failed\n");
- return -1;
- }
-
- errno = 0;
- while((dir_entry = readdir(dir))) {
- if(dir_entry->d_name[0] == '.')
- continue;
- counter++;
- }
- if(errno) {
- fprintf(stderr, "readdir() failed\n");
- return -1;
- }
- closedir(dir);
- return counter;
-}
-
int tree(const char *path, const char *prefix)
{
DIR *main_dir;
@@ -91,10 +58,6 @@ int tree(const char *path, const char *prefix)
i++;
}
closedir(main_dir);
- if(errno) {
- perror("opendir");
- return 1;
- }
entries_sort(entries, cnt_ent);
for(i = 0; i < cnt_ent; i++) {
@@ -109,7 +72,7 @@ int tree(const char *path, const char *prefix)
}
full_path = xstrcat(path, entries[i], "/");
- if(is_dir(full_path)) {
+ if(file_exist(full_path) == F_ISDIR) {
printf("%s%s%s%s%s\n", prefix, pointer, ANSIC_BBLU,
entries[i], ANSIC_RST);