5 /* libpayload headers */
8 int fail(const char* str
)
10 fprintf(stderr
, "%s", str
);
14 int main(int argc
, char** argv
)
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");
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");
24 void *data
= malloc(size
);
25 if (!data
) fail("could not allocate buffer\n");
27 if (fread(data
, size
, 1, cbfs
) != 1) fail("could not read data\n");
28 if (fclose(cbfs
)) fail("could not close file\n");
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");