diff options
| author | @syxhe <https://t.me/syxhe> | 2025-04-15 17:22:41 -0500 |
|---|---|---|
| committer | @syxhe <https://t.me/syxhe> | 2025-04-15 17:22:41 -0500 |
| commit | fce48bb669691b6d3690b032f7a88e22c6f5614a (patch) | |
| tree | 3a7fd47baef1d0b1601a955ba2992a423ae874a9 /src | |
| parent | d9d142a7ad0bade65b6f8b777259e203dc6d5301 (diff) | |
Make some progress on scanning code
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile | 14 | ||||
| -rwxr-xr-x | src/depend.sh | 2 | ||||
| -rw-r--r-- | src/main.c | 33 |
3 files changed, 41 insertions, 8 deletions
diff --git a/src/Makefile b/src/Makefile index 88c5344..e32f72b 100644 --- a/src/Makefile +++ b/src/Makefile | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | CC = gcc | 1 | CC = gcc |
| 2 | SHELL := bash | 2 | SHELL := /usr/bin/env |
| 3 | .SHELLFLAGS := -S bash -c | ||
| 3 | 4 | ||
| 4 | # I need to get better at makefiles so I can write this in a way that isn't absolutely insane/stupid | 5 | # I need to get better at makefiles so I can write this in a way that isn't absolutely insane/stupid |
| 5 | # RELEASE_CFLAGS := -O3 -fipa-pta -fipa-cp -fuse-linker-plugin -flto=auto | 6 | # RELEASE_CFLAGS := -O3 -fipa-pta -fipa-cp -fuse-linker-plugin -flto=auto |
| @@ -11,18 +12,19 @@ LDFLAGS += $$(pkg-config --libs-only-L libsodium) | |||
| 11 | 12 | ||
| 12 | SOURCES := $(wildcard *.c) | 13 | SOURCES := $(wildcard *.c) |
| 13 | OBJECTS := $(patsubst %.c,%.o,$(SOURCES)) | 14 | OBJECTS := $(patsubst %.c,%.o,$(SOURCES)) |
| 14 | DEPS := $(patsubst %.c,%.dep,$(SOURCES)) | 15 | DEPS := $(patsubst %.c,%.d,$(SOURCES)) |
| 15 | 16 | ||
| 16 | .PHONY: all c clean val | 17 | .PHONY: all c clean val |
| 17 | .DELETE_ON_ERROR: | 18 | .DELETE_ON_ERROR: |
| 18 | .ONESHELL: | 19 | .ONESHELL: |
| 19 | 20 | ||
| 20 | all: main | 21 | all: main |
| 21 | main: main.o encryption.o shared.o ll.o arena.o | 22 | main: $(OBJECTS) |
| 22 | 23 | ||
| 23 | $(OBJECTS): %.o: %.dep | 24 | $(OBJECTS): %.o: %.d |
| 24 | %.dep: %.c | 25 | include $(DEPS) # Make sure the dependencies are actually included |
| 25 | ./depend.sh `dirname $*` $(CFLAGS) $*.c > $@ | 26 | %.d: %.c |
| 27 | ./depend.sh $$(dirname $*) $(CFLAGS) $*.c > $@ | ||
| 26 | 28 | ||
| 27 | c clean: | 29 | c clean: |
| 28 | @-rm -rv main $(OBJECTS) $(DEPS) $(wildcard *.test*) $(wildcard *.enc) | 30 | @-rm -rv main $(OBJECTS) $(DEPS) $(wildcard *.test*) $(wildcard *.enc) |
diff --git a/src/depend.sh b/src/depend.sh index b6084b1..7b3caa7 100755 --- a/src/depend.sh +++ b/src/depend.sh | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | #!/bin/bash | 1 | #!/usr/bin/env -S bash |
| 2 | DIR="$1" | 2 | DIR="$1" |
| 3 | shift 1 | 3 | shift 1 |
| 4 | case "$DIR" in | 4 | case "$DIR" in |
| @@ -1,3 +1,5 @@ | |||
| 1 | #define _GNU_SOURCE | ||
| 2 | |||
| 1 | #include "shared.h" | 3 | #include "shared.h" |
| 2 | #include "arena.h" | 4 | #include "arena.h" |
| 3 | #include "encryption.h" | 5 | #include "encryption.h" |
| @@ -9,8 +11,37 @@ | |||
| 9 | 11 | ||
| 10 | #include <string.h> | 12 | #include <string.h> |
| 11 | #include <stdlib.h> | 13 | #include <stdlib.h> |
| 14 | |||
| 15 | |||
| 16 | #include <dirent.h> | ||
| 17 | int selector(const struct dirent *ent) { | ||
| 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 | |||
| 12 | int main() { | 25 | int main() { |
| 13 | error(1, ENOTSUP, "No main file lol"); | 26 | // error(1, ENOTSUP, "No main file lol"); |
| 27 | |||
| 28 | // Sample code on scanning the file system | ||
| 29 | |||
| 30 | struct dirent **namelist = NULL; | ||
| 31 | int numentries = scandir(".", &namelist, selector, alphasort); | ||
| 32 | if(numentries < 0) | ||
| 33 | error(1, errno, "Ran into error scanning dir"); | ||
| 34 | |||
| 35 | dlinkedlist *ll = dlinkedlist_init(); | ||
| 36 | for(int i = 0; i < numentries; i++) { | ||
| 37 | if(dlinkedlist_append(ll, (void *)namelist[i], free) != 0) | ||
| 38 | error(1, errno, "Could not add file entry to linked list"); | ||
| 39 | |||
| 40 | free(namelist[i]); | ||
| 41 | } | ||
| 42 | free(namelist); | ||
| 43 | |||
| 44 | dlinkedlist_free(&ll); | ||
| 14 | 45 | ||
| 15 | return 0; | 46 | return 0; |
| 16 | } \ No newline at end of file | 47 | } \ No newline at end of file |
