summaryrefslogtreecommitdiff
path: root/list.c
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2026-01-21 22:43:38 +0100
committerMitja Felicijan <mitja.felicijan@gmail.com>2026-01-21 22:43:38 +0100
commitd6d9cb137d1f0f75fd68381ec699f76b518061d5 (patch)
treeba482b3cfc1b2a75b832a9bcb2ee52b4bf51394c /list.c
parent5d8dfe892a2ea89f706ee140c3bdcfd89fe03fda (diff)
downloadcrep-d6d9cb137d1f0f75fd68381ec699f76b518061d5.tar.gz
Enable single file processing
Diffstat (limited to 'list.c')
-rw-r--r--list.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/list.c b/list.c
index 8c5b478..e1d4ffd 100644
--- a/list.c
+++ b/list.c
@@ -23,6 +23,17 @@ void add_file_path(Node **head, char *file_path) {
23} 23}
24 24
25void list_files_recursively(char *base_path, Node **head) { 25void list_files_recursively(char *base_path, Node **head) {
26 struct stat statbuf;
27 if (stat(base_path, &statbuf) == -1) {
28 perror("stat");
29 return;
30 }
31
32 if (S_ISREG(statbuf.st_mode)) {
33 add_file_path(head, base_path);
34 return;
35 }
36
26 char path[2048]; 37 char path[2048];
27 struct dirent *dp; 38 struct dirent *dp;
28 DIR *dir = opendir(base_path); 39 DIR *dir = opendir(base_path);
@@ -39,11 +50,10 @@ void list_files_recursively(char *base_path, Node **head) {
39 continue; 50 continue;
40 } 51 }
41 52
42 struct stat statbuf;
43 if (stat(path, &statbuf) != -1) { 53 if (stat(path, &statbuf) != -1) {
44 if (S_ISDIR(statbuf.st_mode)) { 54 if (S_ISDIR(statbuf.st_mode)) {
45 list_files_recursively(path, head); 55 list_files_recursively(path, head);
46 } else { 56 } else if (S_ISREG(statbuf.st_mode)) {
47 add_file_path(head, path); 57 add_file_path(head, path);
48 } 58 }
49 } 59 }