summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author@syxhe <https://t.me/syxhe>2024-12-26 21:42:53 -0600
committer@syxhe <https://t.me/syxhe>2024-12-26 21:42:53 -0600
commit03c5fce0220d3e5d02d320f925a3b9401a397729 (patch)
treedb27acac8fceee17cace9fa05ddd24fa6fe23cf9 /src
parentf7ded3958a7f3bea16e2c8be55f159f34a45ca61 (diff)
Put some notes down
Diffstat (limited to 'src')
-rw-r--r--src/Makefile9
-rw-r--r--src/main.c23
-rw-r--r--src/shared.c20
-rw-r--r--src/shared.h14
4 files changed, 62 insertions, 4 deletions
diff --git a/src/Makefile b/src/Makefile
index f2f4bf7..d3798bb 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -20,7 +20,10 @@ BINARIES := main
20 20
21all: main 21all: main
22 22
23main: main.c 23main: main.o shared.o
24 24
25clean: 25main.o: main.c shared.h
26 rm -rvf $(BINARIES) \ No newline at end of file 26shared.o: shared.c shared.h
27
28c clean: # huh, didn't think that would work
29 rm -rvf $(BINARIES) $(wildcard *.o) \ No newline at end of file
diff --git a/src/main.c b/src/main.c
index f07684d..bf110c2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,7 +1,28 @@
1#include "shared.h"
2
3#include <errno.h>
4#include <error.h>
1#include <stdio.h> 5#include <stdio.h>
2 6
7#include <fcntl.h>
8#include <dirent.h>
9
10int testfilter(const struct dirent *node) {
11 return 1;
12}
13
3int main() { 14int main() {
4 printf("We do a little trolling it's called we do a little trolling\nGod help us all\n"); 15 // Alright, going to start simple. First: scanning for files. I want to do this quickly and in one motion. No reason to do things in O(n2) time if I can do it in O(n)
16
17 int nnodes = -1;
18 struct dirent **nodes = NULL;
19 if((nnodes = scandir(".", &nodes, testfilter, alphasort)) < 0)
20 error(1, errno, "scandir broke");
21
22 for(int i = 0; i < nnodes; i++) {
23 printf("%s\n", nodes[i]->d_name);
24
25 }
5 26
6 return 0; 27 return 0;
7} \ No newline at end of file 28} \ No newline at end of file
diff --git a/src/shared.c b/src/shared.c
new file mode 100644
index 0000000..5e58de0
--- /dev/null
+++ b/src/shared.c
@@ -0,0 +1,20 @@
1#include "shared.h"
2
3#include <stdlib.h>
4#include <errno.h>
5#include <error.h>
6
7void* xcalloc(size_t nmemb, size_t size) {
8 void *mem = calloc(nmemb, size);
9
10 if(mem == NULL) {
11 #if defined ___VXGG___XCALLOC_EXIT_ON_ERROR___ && ___VXGG___XCALLOC_EXIT_ON_ERROR___ > 0
12 error(1, errno, "<xcalloc> Could not allocate memory");
13 #endif
14
15 abort();
16 }
17
18
19 return mem;
20} \ No newline at end of file
diff --git a/src/shared.h b/src/shared.h
new file mode 100644
index 0000000..ac214f7
--- /dev/null
+++ b/src/shared.h
@@ -0,0 +1,14 @@
1#ifndef __VXGG_REWRITE___SHARED_H___3880294315821___
2#define __VXGG_REWRITE___SHARED_H___3880294315821___
3
4#include <stddef.h>
5
6// Defines how `xcalloc()` should exit. `___VXGG___XCALLOC_EXIT_ON_ERROR___ > 0` calls `error()`, and thus functions registered with
7// `atexit()` and `on_exit()`. `___VXGG___XCALLOC_EXIT_ON_ERROR___ <= 0` calls `abort()` on error. `xcalloc()` will ALWAYS 'abort',
8// doing otherwise defeats the purpose of the function
9#define ___VXGG___XCALLOC_EXIT_ON_ERROR___ 1
10
11// `calloc()` with error checking. Calls `error()` or `abort()` on error depending on the value of `___VXGG___XCALLOC_EXIT_ON_ERROR___`
12void* xcalloc(size_t nmemb, size_t size);
13
14#endif \ No newline at end of file