|
47 | 47 | #endif |
48 | 48 |
|
49 | 49 | static void |
| 50 | +seek_expect(int fd, off_t offset, int whence, off_t expect_offset) |
| 51 | +{ |
| 52 | + errno = 0; |
| 53 | + off_t seek_offset = lseek(fd, offset, whence); |
| 54 | + if (seek_offset == expect_offset) |
| 55 | + return; |
| 56 | + |
| 57 | + int err = errno; |
| 58 | + fprintf(stderr, "lseek(fd, %ld, SEEK_%s) = %ld (expected %ld)", |
| 59 | + offset, (whence == SEEK_DATA ? "DATA" : "HOLE"), |
| 60 | + seek_offset, expect_offset); |
| 61 | + if (err != 0) |
| 62 | + fprintf(stderr, " (errno %d [%s])\n", err, strerror(err)); |
| 63 | + else |
| 64 | + fputc('\n', stderr); |
| 65 | + exit(2); |
| 66 | +} |
| 67 | + |
| 68 | +static inline void |
50 | 69 | seek_data(int fd, off_t offset, off_t expected) |
51 | 70 | { |
52 | | - off_t data_offset = lseek(fd, offset, SEEK_DATA); |
53 | | - if (data_offset != expected) { |
54 | | - fprintf(stderr, "lseek(fd, %d, SEEK_DATA) = %d (expected %d)\n", |
55 | | - (int)offset, (int)data_offset, (int)expected); |
56 | | - exit(2); |
57 | | - } |
| 71 | + seek_expect(fd, offset, SEEK_DATA, expected); |
58 | 72 | } |
59 | 73 |
|
60 | | -static void |
| 74 | +static inline void |
61 | 75 | seek_hole(int fd, off_t offset, off_t expected) |
62 | 76 | { |
63 | | - off_t hole_offset = lseek(fd, offset, SEEK_HOLE); |
64 | | - if (hole_offset != expected) { |
65 | | - fprintf(stderr, "lseek(fd, %d, SEEK_HOLE) = %d (expected %d)\n", |
66 | | - (int)offset, (int)hole_offset, (int)expected); |
67 | | - exit(2); |
68 | | - } |
| 77 | + seek_expect(fd, offset, SEEK_HOLE, expected); |
69 | 78 | } |
70 | 79 |
|
71 | 80 | int |
|
0 commit comments