about summary refs log tree commit diff
path: root/allocfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'allocfile.c')
-rw-r--r--allocfile.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/allocfile.c b/allocfile.c
new file mode 100644
index 0000000..d4d17f8
--- /dev/null
+++ b/allocfile.c
@@ -0,0 +1,19 @@
+#include "cccl.h"
+
+#include <stdlib.h>
+
+#include <sys/stat.h>
+
+
+int cccl_allocfile(const char *path, struct cccl_File *file)
+{
+    struct stat st;
+    int err = stat(path, &st);
+    if (err)
+        return err;
+
+    file->size = st.st_size;
+    file->buffer = malloc(file->size);
+
+    return !file->buffer;
+}