summaryrefslogtreecommitdiff
path: root/src/scanner.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/scanner.c')
-rw-r--r--src/scanner.c49
1 files changed, 25 insertions, 24 deletions
diff --git a/src/scanner.c b/src/scanner.c
index ea35e3c..2ffbea4 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -1,7 +1,6 @@
1#define _GNU_SOURCE 1#define _GNU_SOURCE
2#include "shared.h" 2#include "shared.h"
3 3
4#include "ll.h"
5#include "scanner.h" 4#include "scanner.h"
6 5
7#include <stdlib.h> 6#include <stdlib.h>
@@ -10,27 +9,29 @@
10#include <errno.h> 9#include <errno.h>
11#include <error.h> 10#include <error.h>
12 11
13dlinkedlist * scandirlist(const char * const dir, int (*selector)(const struct dirent *), int (*cmp)(const struct dirent **, const struct dirent **)) { 12// dlinkedlist * scandirlist(const char * const dir, int (*selector)(const struct dirent *), int (*cmp)(const struct dirent **, const struct dirent **)) {
14 if(!dir || selector == NULL || cmp == NULL) ERRRET(EINVAL, NULL); 13// if(!dir || selector == NULL || cmp == NULL) ERRRET(EINVAL, NULL);
15 14
16 struct dirent **namelist = NULL; 15// struct dirent **namelist = NULL;
17 dlinkedlist *list = NULL; 16// dlinkedlist *list = NULL;
18 int numentries = -1; 17// int numentries = -1;
19 18
20 if((numentries = scandir(dir, &namelist, selector, cmp)) < 0) 19// if((numentries = scandir(dir, &namelist, selector, cmp)) < 0)
21 ERRRET(errno, NULL); 20// ERRRET(errno, NULL);
22 21
23 list = dlinkedlist_init(); 22// list = dlinkedlist_init();
24 for(int i = 0; i < numentries; i++) 23// for(int i = 0; i < numentries; i++)
25 if(dlinkedlist_append(list, (void *)(namelist[i]), free) < 0) { 24// if(dlinkedlist_append(list, (void *)(namelist[i]), free) < 0) {
26 dlinkedlist_free(list); 25// dlinkedlist_free(list);
27 for(int j = i; j < numentries; j++) 26// for(int j = i; j < numentries; j++)
28 free(namelist[j]); 27// free(namelist[j]);
29 28
30 free(namelist); 29// free(namelist);
31 ERRRET(errno, NULL); 30// ERRRET(errno, NULL);
32 } 31// }
33 free(namelist); 32// free(namelist);
34 33
35 return list; 34// return list;
36} 35// }
36
37// TODO: Rewrite this to use the threadpool. Each newly scanned file should be pushed onto the threadpool as an encryption task \ No newline at end of file