* 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. */
| 36 | * @return On success number of bytes read is returned. On failure -1 is returned. |
| 37 | */ |
| 38 | int 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 | } |
no test coverage detected