summaryrefslogtreecommitdiff
path: root/src/main.c
blob: cacbc4fc2f7154ec77bcf5c7f2c9f8bc6fa2c707 (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
38
39
40
41
42
43
44
45
46
47
#define _GNU_SOURCE

#include "shared.h"
#include "arena.h"
#include "encryption.h"
#include "ll.h"

#include <errno.h>
#include <error.h>
#include <stdio.h>

#include <string.h>
#include <stdlib.h>


#include <dirent.h>
int selector(const struct dirent *ent) {
    // non-zero value includes a file, zero value excludes it
    if(strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
        return 0;

    return 1;
}

int main() {
    // error(1, ENOTSUP, "No main file lol");

    // Sample code on scanning the file system

    struct dirent **namelist = NULL;
    int numentries = scandir(".", &namelist, selector, alphasort);
    if(numentries < 0)
        error(1, errno, "Ran into error scanning dir");

    dlinkedlist *ll = dlinkedlist_init();
    for(int i = 0; i < numentries; i++) {
        if(dlinkedlist_append(ll, (void *)namelist[i], free) != 0)
            error(1, errno, "Could not add file entry to linked list");
    
        free(namelist[i]);
    }
    free(namelist);

    dlinkedlist_free(&ll);

    return 0;
}