summaryrefslogtreecommitdiff
path: root/src/scanner.c
blob: 2ffbea4c76ca00ad84102680251bca480286d77e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#define _GNU_SOURCE
#include "shared.h"

#include "scanner.h"

#include <stdlib.h>
#include <dirent.h>
#include <string.h>
#include <errno.h>
#include <error.h>

// dlinkedlist * scandirlist(const char * const dir, int (*selector)(const struct dirent *), int (*cmp)(const struct dirent **, const struct dirent **)) {
//     if(!dir || selector == NULL || cmp == NULL) ERRRET(EINVAL, NULL);
    
//     struct dirent **namelist = NULL;
//     dlinkedlist *list = NULL;
//     int numentries = -1;

//     if((numentries = scandir(dir, &namelist, selector, cmp)) < 0)
//         ERRRET(errno, NULL);

//     list = dlinkedlist_init();
//     for(int i = 0; i < numentries; i++)
//         if(dlinkedlist_append(list, (void *)(namelist[i]), free) < 0) {
//             dlinkedlist_free(list);
//             for(int j = i; j < numentries; j++)
//                 free(namelist[j]);

//             free(namelist);
//             ERRRET(errno, NULL);
//         }
//     free(namelist);

//     return list;
// }

// TODO: Rewrite this to use the threadpool. Each newly scanned file should be pushed onto the threadpool as an encryption task