1 /* system headers */
2 #include <stdlib.h>
3 #include <stdio.h>
4
5 /* libpayload headers */
6 #include "cbfs.h"
7
fail(const char * str)8 int fail(const char* str)
9 {
10 fprintf(stderr, "%s", str);
11 exit(1);
12 }
13
main(int argc,char ** argv)14 int main(int argc, char** argv)
15 {
16 FILE *cbfs = fopen("data/cbfs-x86.bin", "rb");
17 if (!cbfs) fail("could not open test file\n");
18 if (fseek(cbfs, 0, SEEK_END) != 0) fail("seek to end failed\n");
19
20 long size = ftell(cbfs);
21 if (size == -1) fail("could not determine file size\n");
22 if (fseek(cbfs, 0, SEEK_SET) != 0) fail("seek to start failed\n");
23
24 void *data = malloc(size);
25 if (!data) fail("could not allocate buffer\n");
26
27 if (fread(data, size, 1, cbfs) != 1) fail("could not read data\n");
28 if (fclose(cbfs)) fail("could not close file\n");
29
30 if (setup_cbfs_from_ram(data, size) != 0) fail("could not setup CBFS in RAM\n");
31 struct cbfs_file *file = cbfs_find("foo");
32 if (file == NULL) fail("could not find file in CBFS\n");
33 exit(0);
34 }
35