Patchwork [v4,2/9] 3 new file wrappers

login
register
mail settings
Submitter Stefan Berger
Date March 21, 2013, 6:29 p.m.
Message ID <1363890571-15146-3-git-send-email-stefanb@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/229795/
State New
Headers show

Comments

Stefan Berger - March 21, 2013, 6:29 p.m.
Add 3 very short file wrapper functions to make code that follows more
readable.

Cc: Michael Tsirkin <mst@redhat.com>
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Signed-off-by: Joel Schopp <jschopp@linux.vnet.ibm.com>
---
 include/migration/qemu-file.h |  3 +++
 util/qemu-file.c              | 30 ++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

Patch

diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h
index 7194b84..728b6e2 100644
--- a/include/migration/qemu-file.h
+++ b/include/migration/qemu-file.h
@@ -68,6 +68,9 @@  int qemu_fclose(QEMUFile *f);
 int64_t qemu_ftell(QEMUFile *f);
 void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
 void qemu_put_byte(QEMUFile *f, int v);
+int qemu_read_bytes(QEMUFile *f, uint8_t *buf, int size);
+int qemu_peek_bytes(QEMUFile *f, uint8_t *buf, int size, size_t offset);
+int qemu_write_bytes(QEMUFile *f, const uint8_t *buf, int size);
 
 static inline void qemu_put_ubyte(QEMUFile *f, unsigned int v)
 {
diff --git a/util/qemu-file.c b/util/qemu-file.c
index 4fed6d5..f8a54e7 100644
--- a/util/qemu-file.c
+++ b/util/qemu-file.c
@@ -713,3 +713,33 @@  uint64_t qemu_get_be64(QEMUFile *f)
     return v;
 }
 
+int qemu_read_bytes(QEMUFile *f, uint8_t *buf, int size)
+{
+    if (qemu_file_get_error(f)) {
+        return -1;
+    }
+    return qemu_get_buffer(f, buf, size);
+}
+
+int qemu_peek_bytes(QEMUFile *f, uint8_t *buf, int size, size_t offset)
+{
+    if (qemu_file_get_error(f)) {
+        return -1;
+    }
+    return qemu_peek_buffer(f, buf, size, offset);
+}
+
+int qemu_write_bytes(QEMUFile *f, const uint8_t *buf, int size)
+{
+    if (qemu_file_get_error(f)) {
+        return -1;
+    }
+
+    qemu_put_buffer(f, buf, size);
+
+    if (qemu_file_get_error(f)) {
+        return -1;
+    }
+
+    return size;
+}