MCPcopy Create free account
hub / github.com/coreboot/coreboot / test_read_file

Function test_read_file

tests/helpers/file.c:38–51  ·  view source on GitHub ↗

* Read a file and write its contents into a buffer * * @params fname name of the file relative to the __TEST_DATA_DIR__ directory * @params buf buffer to write file contents into * @params size size of buf * * @return On success number of bytes read is returned. On failure -1 is returned. */

Source from the content-addressed store, hash-verified

36 * @return On success number of bytes read is returned. On failure -1 is returned.
37 */
38int test_read_file(const char *fname, uint8_t *buf, size_t size)
39{
40 char path[strlen(__TEST_DATA_DIR__) + strlen(fname) + 2];
41 sprintf(path, "%s/%s", __TEST_DATA_DIR__, fname);
42
43 int f = open(path, O_RDONLY);
44 if (f == -1)
45 return -1;
46
47 int read_size = read(f, buf, size);
48
49 close(f);
50 return read_size;
51}

Callers 2

test_ulzman_correct_fileFunction · 0.85

Calls 3

strlenFunction · 0.85
sprintfFunction · 0.85
readFunction · 0.85

Tested by

no test coverage detected