summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2019-07-12 15:34:26 +0200
committerPaweł Redman <pawel.redman@gmail.com>2019-07-12 15:34:26 +0200
commitac855a7e9d9970e4f1b658b679c05c893d991be7 (patch)
tree9c1d1b21ddfa8bc57f6d7d885659995dedaa6950 /src/main.c
Initial commit
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