diff options
author | Keir Fraser <keir@xensource.com> | 2007-11-11 18:22:33 +0000 |
---|---|---|
committer | Keir Fraser <keir@xensource.com> | 2007-11-11 18:22:33 +0000 |
commit | c316590403819d9206b81ca5dd42136c86ee271c (patch) | |
tree | d9728245710b174c84dcbd28d9aba5cdb1d747c2 /tools/libxc/xc_core.c | |
parent | bbceef66ead2fb6800a767a7625c598f196ce852 (diff) | |
download | xen-c316590403819d9206b81ca5dd42136c86ee271c.tar.gz xen-c316590403819d9206b81ca5dd42136c86ee271c.tar.bz2 xen-c316590403819d9206b81ca5dd42136c86ee271c.zip |
libxc: Consolidate read()/write() syscall wrappers to read/write an
exact number of bytes. The consolidated versions are more watertight
than the various versions previously distributed around the library
source code.
Signed-off-by: Keir Fraser <keir@xensource.com>
Diffstat (limited to 'tools/libxc/xc_core.c')
-rw-r--r-- | tools/libxc/xc_core.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/tools/libxc/xc_core.c b/tools/libxc/xc_core.c index edcf67cfc0..021d069c1c 100644 --- a/tools/libxc/xc_core.c +++ b/tools/libxc/xc_core.c @@ -860,19 +860,15 @@ struct dump_args { static int local_file_dump(void *args, char *buffer, unsigned int length) { struct dump_args *da = args; - int bytes, offset; - for ( offset = 0; offset < length; offset += bytes ) + if ( write_exact(da->fd, buffer, length) == -1 ) { - bytes = write(da->fd, &buffer[offset], length-offset); - if ( bytes <= 0 ) - { - PERROR("Failed to write buffer"); - return -errno; - } + PERROR("Failed to write buffer"); + return -errno; } - if (length >= DUMP_INCREMENT*PAGE_SIZE) { + if ( length >= (DUMP_INCREMENT * PAGE_SIZE) ) + { // Now dumping pages -- make sure we discard clean pages from // the cache after each write discard_file_cache(da->fd, 0 /* no flush */); |