about summary refs log tree commit diff
path: root/main.c
diff options
context:
space:
mode:
authorNakidai <nakidai@disroot.org>2025-03-24 21:01:37 +0300
committerNakidai <nakidai@disroot.org>2025-03-24 21:01:37 +0300
commitf312b357ab2ec3cf83a67945f3641b964a59e8d2 (patch)
tree425f3371eee770f64e268e9964dba29ad17bd410 /main.c
parentad9d6a199db7c28f8b20f131dfb55a26e0e251de (diff)
download3cl-f312b357ab2ec3cf83a67945f3641b964a59e8d2.tar.gz
3cl-f312b357ab2ec3cf83a67945f3641b964a59e8d2.zip
Add code
Diffstat (limited to 'main.c')
-rw-r--r--main.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..a5f79e7
--- /dev/null
+++ b/main.c
@@ -0,0 +1,42 @@
+#include "cccl.h"
+
+#include <assert.h>
+#include <err.h>
+#include <stdio.h>
+
+
+int main(int argc, char **argv)
+{
+    if (!argv[1])
+        return 1;
+
+    struct cccl_File file;
+
+    int error = cccl_allocfile(argv[1], &file);
+    if (error)
+        err(1, "cccl_readfile()");
+
+    FILE *f = fopen(argv[1], "r");
+    if (!f)
+        err(1, "fopen()");
+    int bytes_read = 0;
+    while (bytes_read < file.size)
+    {
+        int read_now = fread(
+            file.buffer + bytes_read,
+            sizeof(*file.buffer),
+            (file.size - bytes_read) % 2048,
+            f
+        );
+        if (read_now == 0)
+        {
+            if (ferror(f))
+                errx(1, "couldn't read %s", argv[1]);
+            else
+                break;
+        }
+    }
+    fclose(f);
+
+    cccl(file);
+}