1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#include "common.h"
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include "e2e.h"
#include "export.h"
int main(int argc, char **argv)
{
int ret = 0;
char *inpath;
int fd;
struct stat st;
void *input;
struct e2e_data data;
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");
ret = 1;
goto error_mmap;
}
input = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (!input) {
perror("mmap");
ret = 1;
goto error_mmap;
}
if (errno = e2e_read(&data, input, input + st.st_size))
perror("e2e_read");
else if (errno = export(&data, "testing.mat"))
perror("export");
e2e_destroy(&data);
munmap(input, st.st_size);
error_mmap:
close(fd);
return ret;
}
|