diff options
| author | Jan Sucan <jan@jansucan.com> | 2021-06-06 13:51:00 +0200 |
|---|---|---|
| committer | Jan Sucan <jan@jansucan.com> | 2021-06-06 13:51:00 +0200 |
| commit | 37677a62c3d4baa4c70cefd9646ba62fd1e62649 (patch) | |
| tree | 1b70b6fe3c6689f3387a5752a8e4f133b71511b9 /src/file.c | |
| parent | f1ced068f1eccdf2866a91334d4e271e8f94802d (diff) | |
Fix restoring a diff image
Diffstat (limited to 'src/file.c')
| -rw-r--r-- | src/file.c | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -48,3 +48,20 @@ file_size(FILE *const file) return size; } + +size_t +file_read_sectors(FILE *const file, char *const buffer, uint32_t buffer_size, + uint32_t sector_size) +{ + const size_t bytes_read = fread(buffer, 1U, buffer_size, file); + + if (ferror(file)) { + print_error("cannot read from file: %s", strerror(errno)); + return 0; + } else if ((bytes_read % sector_size) != 0) { + print_error("data read from input file is not multiple of sector size"); + return 0; + } else { + return (bytes_read / sector_size); + } +} |
