From fce48bb669691b6d3690b032f7a88e22c6f5614a Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Tue, 15 Apr 2025 17:22:41 -0500 Subject: Make some progress on scanning code --- src/Makefile | 14 ++++++++------ src/depend.sh | 2 +- src/main.c | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Makefile b/src/Makefile index 88c5344..e32f72b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,6 @@ CC = gcc -SHELL := bash +SHELL := /usr/bin/env +.SHELLFLAGS := -S bash -c # I need to get better at makefiles so I can write this in a way that isn't absolutely insane/stupid # RELEASE_CFLAGS := -O3 -fipa-pta -fipa-cp -fuse-linker-plugin -flto=auto @@ -11,18 +12,19 @@ LDFLAGS += $$(pkg-config --libs-only-L libsodium) SOURCES := $(wildcard *.c) OBJECTS := $(patsubst %.c,%.o,$(SOURCES)) -DEPS := $(patsubst %.c,%.dep,$(SOURCES)) +DEPS := $(patsubst %.c,%.d,$(SOURCES)) .PHONY: all c clean val .DELETE_ON_ERROR: .ONESHELL: all: main -main: main.o encryption.o shared.o ll.o arena.o +main: $(OBJECTS) -$(OBJECTS): %.o: %.dep -%.dep: %.c - ./depend.sh `dirname $*` $(CFLAGS) $*.c > $@ +$(OBJECTS): %.o: %.d +include $(DEPS) # Make sure the dependencies are actually included +%.d: %.c + ./depend.sh $$(dirname $*) $(CFLAGS) $*.c > $@ c clean: @-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 @@ -#!/bin/bash +#!/usr/bin/env -S bash DIR="$1" shift 1 case "$DIR" in diff --git a/src/main.c b/src/main.c index fc1044a..cacbc4f 100644 --- a/src/main.c +++ b/src/main.c @@ -1,3 +1,5 @@ +#define _GNU_SOURCE + #include "shared.h" #include "arena.h" #include "encryption.h" @@ -9,8 +11,37 @@ #include #include + + +#include +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"); + // 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; } \ No newline at end of file -- cgit v1.2.3