| 1 |
|
| 2 |
|
| 3 |
#include <fcntl.h> |
| 4 |
#include <stdint.h> |
| 5 |
#include <stdio.h> |
| 6 |
#include <string.h> |
| 7 |
#include <sys/stat.h> |
| 8 |
#include <sys/types.h> |
| 9 |
#include <unistd.h> |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
int test_get_file_size(const char *fname) |
| 19 |
{ |
| 20 |
char path[strlen(__TEST_DATA_DIR__) + strlen(fname) + 2]; |
| 21 |
sprintf(path, "%s/%s", __TEST_DATA_DIR__, fname); |
| 22 |
|
| 23 |
struct stat st; |
| 24 |
if (stat(path, &st) == -1) |
| 25 |
return -1; |
| 26 |
return st.st_size; |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 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 |
} |