diff options
Diffstat (limited to 'tools/blktap2/drivers/tapdisk-utils.c')
-rw-r--r-- | tools/blktap2/drivers/tapdisk-utils.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tools/blktap2/drivers/tapdisk-utils.c b/tools/blktap2/drivers/tapdisk-utils.c index 1b15f12154..44840efbf8 100644 --- a/tools/blktap2/drivers/tapdisk-utils.c +++ b/tools/blktap2/drivers/tapdisk-utils.c @@ -175,3 +175,40 @@ int tapdisk_linux_version(void) } #endif +int read_exact(int fd, void *data, size_t size) +{ + size_t offset = 0; + ssize_t len; + + while ( offset < size ) + { + len = read(fd, (char *)data + offset, size - offset); + if ( (len == -1) && (errno == EINTR) ) + continue; + if ( len == 0 ) + errno = 0; + if ( len <= 0 ) + return -1; + offset += len; + } + + return 0; +} + +int write_exact(int fd, const void *data, size_t size) +{ + size_t offset = 0; + ssize_t len; + + while ( offset < size ) + { + len = write(fd, (const char *)data + offset, size - offset); + if ( (len == -1) && (errno == EINTR) ) + continue; + if ( len <= 0 ) + return -1; + offset += len; + } + + return 0; +} |