From 069301a603ad07338179bafed0c35b6fe3b372f2 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Thu, 22 Jan 2026 02:24:44 +0100 Subject: Better arg parsing --- list.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'list.c') 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); } -- cgit v1.2.3