diff options
| author | @syxhe <https://t.me/syxhe> | 2025-04-15 18:50:57 -0500 |
|---|---|---|
| committer | @syxhe <https://t.me/syxhe> | 2025-04-15 18:51:49 -0500 |
| commit | 9d3c8770ec63fe3e02f82bdc244e63d701492322 (patch) | |
| tree | 708ef0a2059f00ae8ff5e8cf12c5c0bd37cf0e0c /src/main.c | |
| parent | 54b82706a01049e4ed5e4d417f50f642c701105b (diff) | |
Create scanner.c/h files
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 37 |
1 files changed, 10 insertions, 27 deletions
| @@ -1,9 +1,11 @@ | |||
| 1 | #define _GNU_SOURCE | 1 | #define _GNU_SOURCE |
| 2 | 2 | ||
| 3 | #include "shared.h" | ||
| 4 | #include "arena.h" | 3 | #include "arena.h" |
| 5 | #include "encryption.h" | ||
| 6 | #include "ll.h" | 4 | #include "ll.h" |
| 5 | #include "encryption.h" | ||
| 6 | #include "scanner.h" | ||
| 7 | #include "shared.h" | ||
| 8 | |||
| 7 | 9 | ||
| 8 | #include <errno.h> | 10 | #include <errno.h> |
| 9 | #include <error.h> | 11 | #include <error.h> |
| @@ -14,38 +16,19 @@ | |||
| 14 | 16 | ||
| 15 | 17 | ||
| 16 | #include <dirent.h> | 18 | #include <dirent.h> |
| 17 | int selector(const struct dirent *ent) { | 19 | int lol(const struct dirent *node) {return 1;} |
| 18 | // non-zero value includes a file, zero value excludes it | ||
| 19 | if(strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) | ||
| 20 | return 0; | ||
| 21 | |||
| 22 | return 1; | ||
| 23 | } | ||
| 24 | |||
| 25 | int printnames(void *data) { | 20 | int printnames(void *data) { |
| 26 | struct dirent *node = (struct dirent *)data; | 21 | printf("%s\n", (data) ? ((struct dirent *)data)->d_name : "null"); |
| 27 | |||
| 28 | printf("%s\n", (node) ? node->d_name : "null"); | ||
| 29 | return 0; | 22 | return 0; |
| 30 | } | 23 | } |
| 31 | |||
| 32 | int main() { | 24 | int main() { |
| 33 | // error(1, ENOTSUP, "No main file lol"); | 25 | // error(1, ENOTSUP, "No main file lol"); |
| 34 | 26 | ||
| 35 | // Sample code on scanning the file system | 27 | // Test code to showcase the scanner function |
| 36 | |||
| 37 | struct dirent **namelist = NULL; | ||
| 38 | int numentries = scandir(".", &namelist, selector, alphasort); | ||
| 39 | if(numentries < 0) | ||
| 40 | error(1, errno, "Ran into error scanning dir"); | ||
| 41 | 28 | ||
| 42 | dlinkedlist *list = dlinkedlist_init(); | 29 | dlinkedlist *ll = scandirlist(".", lol, alphasort); |
| 43 | for(int i = 0; i < numentries; i++) | 30 | dlinkedlist_foreach(ll, printnames); |
| 44 | dlinkedlist_append(list, (void *)(namelist[i]), free); | 31 | dlinkedlist_free(ll); |
| 45 | free(namelist); | ||
| 46 | |||
| 47 | dlinkedlist_foreach(list, printnames); | ||
| 48 | dlinkedlist_free(list); | ||
| 49 | 32 | ||
| 50 | return 0; | 33 | return 0; |
| 51 | } \ No newline at end of file | 34 | } \ No newline at end of file |
