summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..e51d863
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,55 @@
+#include <stdlib.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+
+#include "e2e.h"
+
+uint32_t u32le(const char*);
+
+int main(int argc, char **argv)
+{
+ int rv = 0;
+ char *inpath;
+ int fd;
+ struct stat st;
+ void *input;
+
+ if (argc < 2) {
+ fprintf(stderr, "%s [FILE]\n", argv[0]);
+ return 1;
+ }
+
+ inpath = argv[1];
+
+ fd = open(inpath, O_RDONLY);
+ if (fd == -1) {
+ perror("open");
+ return 1;
+ }
+
+ if (fstat(fd, &st) == -1) {
+ perror("fstat");
+ rv = 1;
+ goto error_mmap;
+ }
+
+ input = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+ if (!input) {
+ perror("mmap");
+ rv = 1;
+ goto error_mmap;
+ }
+
+ e2e_read(input, input + st.st_size);
+
+ munmap(input, st.st_size);
+error_mmap:
+ close(fd);
+ return rv;
+} \ No newline at end of file