summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--src/Makefile14
-rwxr-xr-xsrc/depend.sh2
-rw-r--r--src/main.c33
4 files changed, 42 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore
index 72dbe73..9ec7b19 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,4 +7,4 @@ bin/
7*test* 7*test*
8*.enc 8*.enc
9.vscode/ 9.vscode/
10*.dep \ No newline at end of file 10*.d \ No newline at end of file
diff --git a/src/Makefile b/src/Makefile
index 88c5344..e32f72b 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,5 +1,6 @@
1CC = gcc 1CC = gcc
2SHELL := bash 2SHELL := /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
12SOURCES := $(wildcard *.c) 13SOURCES := $(wildcard *.c)
13OBJECTS := $(patsubst %.c,%.o,$(SOURCES)) 14OBJECTS := $(patsubst %.c,%.o,$(SOURCES))
14DEPS := $(patsubst %.c,%.dep,$(SOURCES)) 15DEPS := $(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
20all: main 21all: main
21main: main.o encryption.o shared.o ll.o arena.o 22main: $(OBJECTS)
22 23
23$(OBJECTS): %.o: %.dep 24$(OBJECTS): %.o: %.d
24%.dep: %.c 25include $(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
27c clean: 29c 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
2DIR="$1" 2DIR="$1"
3shift 1 3shift 1
4case "$DIR" in 4case "$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 @@
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>
17int 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
12int main() { 25int 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