tree(): Refactor, flatten tree

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2017-07-02 16:32:04 +02:00
1 parent 441d5f58d7
commit 32c774deef
1 file changed
+6 -8
+6 -8
View File
@@ -59,15 +59,17 @@ static void get_perms(struct stat *st, char *buf, size_t len)
static int descend(char *path, int show_perms, char *pfx) static int descend(char *path, int show_perms, char *pfx)
{ {
int result = 0; int i, n, result = 0;
struct stat st; struct stat st;
struct dirent **namelist = NULL;
if (-1 == lstat(path, &st)) if (-1 == lstat(path, &st))
return 1; return 1;
if ((st.st_mode & S_IFMT) == S_IFDIR) { if ((st.st_mode & S_IFMT) != S_IFDIR) {
int i, n; errno = ENOTDIR;
struct dirent **namelist = NULL; return -1;
}
n = scandir(path, &namelist, filter, alphasort); n = scandir(path, &namelist, filter, alphasort);
if (n) { if (n) {
@@ -106,10 +108,6 @@ static int descend(char *path, int show_perms, char *pfx)
free(namelist); free(namelist);
} }
} else {
errno = ENOTDIR;
result = -1;
}
return result; return result;
} }