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/scanner.c | |
| parent | 54b82706a01049e4ed5e4d417f50f642c701105b (diff) | |
Create scanner.c/h files
Diffstat (limited to 'src/scanner.c')
| -rw-r--r-- | src/scanner.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/scanner.c b/src/scanner.c new file mode 100644 index 0000000..7c65df4 --- /dev/null +++ b/src/scanner.c | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | #include "shared.h" | ||
| 2 | #define _GNU_SOURCE | ||
| 3 | |||
| 4 | #include "ll.h" | ||
| 5 | #include "scanner.h" | ||
| 6 | |||
| 7 | #include <stdlib.h> | ||
| 8 | #include <dirent.h> | ||
| 9 | #include <string.h> | ||
| 10 | #include <errno.h> | ||
| 11 | #include <error.h> | ||
| 12 | |||
| 13 | dlinkedlist * scandirlist(const char * const dir, int (*selector)(const struct dirent *), int (*cmp)(const struct dirent **, const struct dirent **)) { | ||
| 14 | struct dirent **namelist = NULL; | ||
| 15 | dlinkedlist *list = NULL; | ||
| 16 | int numentries = -1; | ||
| 17 | |||
| 18 | if((numentries = scandir(dir, &namelist, selector, cmp)) < 0) | ||
| 19 | RETURNWERR(errno, NULL); | ||
| 20 | |||
| 21 | list = dlinkedlist_init(); | ||
| 22 | for(int i = 0; i < numentries; i++) | ||
| 23 | if(dlinkedlist_append(list, (void *)(namelist[i]), free) < 0) { | ||
| 24 | dlinkedlist_free(list); | ||
| 25 | RETURNWERR(errno, NULL); | ||
| 26 | } | ||
| 27 | free(namelist); | ||
| 28 | |||
| 29 | return list; | ||
| 30 | } | ||
