summaryrefslogtreecommitdiff
path: root/list.c
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2026-01-22 02:24:44 +0100
committerMitja Felicijan <mitja.felicijan@gmail.com>2026-01-22 02:24:44 +0100
commit069301a603ad07338179bafed0c35b6fe3b372f2 (patch)
tree74010f542968876938d18effe8939694ddafdc03 /list.c
parentac3c52c4431d422affe951ff0641b4eb04787e54 (diff)
downloadcrep-069301a603ad07338179bafed0c35b6fe3b372f2.tar.gz
Better arg parsing
Diffstat (limited to 'list.c')
-rw-r--r--list.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/list.c b/list.c
index e1d4ffd..71e70c8 100644
--- a/list.c
+++ b/list.c
@@ -22,7 +22,7 @@ void add_file_path(Node **head, char *file_path) {
*head = new;
}
-void list_files_recursively(char *base_path, Node **head) {
+void list_files_recursively(char *base_path, Node **head, int max_depth, int current_depth) {
struct stat statbuf;
if (stat(base_path, &statbuf) == -1) {
perror("stat");
@@ -52,7 +52,9 @@ void list_files_recursively(char *base_path, Node **head) {
if (stat(path, &statbuf) != -1) {
if (S_ISDIR(statbuf.st_mode)) {
- list_files_recursively(path, head);
+ if (max_depth == -1 || current_depth < max_depth) {
+ list_files_recursively(path, head, max_depth, current_depth + 1);
+ }
} else if (S_ISREG(statbuf.st_mode)) {
add_file_path(head, path);
}