qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Joel Schopp <jschopp@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Joel Schopp <jschopp@linux.vnet.ibm.com>,
	Stefan Berger <stefanb@linux.vnet.ibm.com>,
	Michael Tsirkin <mst@redhat.com>
Subject: [Qemu-devel] [PATCH 3/9] two new file wrappers
Date: Wed, 13 Mar 2013 13:56:22 -0500	[thread overview]
Message-ID: <1363200988-17865-4-git-send-email-jschopp@linux.vnet.ibm.com> (raw)
In-Reply-To: <1363200988-17865-1-git-send-email-jschopp@linux.vnet.ibm.com>

Add a 3 very short file wrapper functions to make code that follows more
readable.  Also export an existing function that is currently static.

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(+)

diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h
index b76a901..07d8362 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 44b52b4..e698713 100644
--- a/util/qemu-file.c
+++ b/util/qemu-file.c
@@ -680,3 +680,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;
+}
-- 
1.7.10.4

  parent reply	other threads:[~2013-03-13 18:57 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-13 18:56 [Qemu-devel] [PATCH 0/9 v3] Implement and test asn1 ber visitors Joel Schopp
2013-03-13 18:56 ` [Qemu-devel] [PATCH 1/9] qemu-file Joel Schopp
2013-03-13 18:56 ` [Qemu-devel] [PATCH 2/9] qapi_c_arrays.diff Joel Schopp
2013-03-13 19:11   ` Anthony Liguori
2013-03-13 22:54   ` Stefan Berger
2013-03-13 18:56 ` Joel Schopp [this message]
2013-03-13 21:04   ` [Qemu-devel] [PATCH 3/9] two new file wrappers Eric Blake
2013-03-14 10:49     ` Stefan Berger
2013-03-13 18:56 ` [Qemu-devel] [PATCH 4/9] qemu_qsb.diff Joel Schopp
2013-03-13 21:11   ` mdroth
2013-03-13 21:28     ` Stefan Berger
2013-03-13 22:41       ` mdroth
2013-03-13 22:47         ` mdroth
2013-03-13 23:11           ` Stefan Berger
2013-03-13 18:56 ` [Qemu-devel] [PATCH 5/9] qapi_sized_buffer Joel Schopp
2013-03-13 20:52   ` mdroth
2013-03-13 22:00     ` Stefan Berger
2013-03-13 23:18       ` mdroth
2013-03-14  1:48         ` Stefan Berger
2013-03-14 12:18           ` mdroth
2013-03-14 13:39             ` Stefan Berger
2013-03-14 14:28               ` mdroth
2013-03-14 14:51                 ` Stefan Berger
2013-03-14 15:11                   ` mdroth
2013-03-14 15:24                     ` Stefan Berger
2013-03-14 21:06                       ` mdroth
2013-03-15  2:05                         ` Stefan Berger
2013-03-13 18:56 ` [Qemu-devel] [PATCH 6/9] asn1_output-visitor.diff Joel Schopp
2013-03-13 18:56 ` [Qemu-devel] [PATCH 7/9] asn1_input-visitor.diff Joel Schopp
2013-03-13 18:56 ` [Qemu-devel] [PATCH 8/9] asn1_test_visitor_serialization.diff Joel Schopp
2013-03-13 18:56 ` [Qemu-devel] [PATCH 9/9] update_maintainers.diff Joel Schopp
  -- strict thread matches above, loose matches on Subject: below --
2013-03-13  3:09 [Qemu-devel] [PATCH 0/9 v2] Implement and test asn1 ber visitors Joel Schopp
2013-03-13  3:09 ` [Qemu-devel] [PATCH 3/9] two new file wrappers Joel Schopp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1363200988-17865-4-git-send-email-jschopp@linux.vnet.ibm.com \
    --to=jschopp@linux.vnet.ibm.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanb@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).