From patchwork Wed Mar 13 03:09:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Schopp X-Patchwork-Id: 227144 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D4B912C02A1 for ; Wed, 13 Mar 2013 14:11:06 +1100 (EST) Received: from localhost ([::1]:53632 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFc5o-0007Tp-UI for incoming@patchwork.ozlabs.org; Tue, 12 Mar 2013 23:11:04 -0400 Received: from eggs.gnu.org ([208.118.235.92]:36484) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFc4z-0007MP-JA for qemu-devel@nongnu.org; Tue, 12 Mar 2013 23:10:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UFc4s-0002UG-2u for qemu-devel@nongnu.org; Tue, 12 Mar 2013 23:10:13 -0400 Received: from e8.ny.us.ibm.com ([32.97.182.138]:35288) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UFc4r-0002TD-Vf for qemu-devel@nongnu.org; Tue, 12 Mar 2013 23:10:06 -0400 Received: from /spool/local by e8.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 12 Mar 2013 23:10:05 -0400 Received: from d01dlp01.pok.ibm.com (9.56.250.166) by e8.ny.us.ibm.com (192.168.1.108) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 12 Mar 2013 23:10:02 -0400 Received: from d01relay03.pok.ibm.com (d01relay03.pok.ibm.com [9.56.227.235]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id 270C238C801C for ; Tue, 12 Mar 2013 23:10:02 -0400 (EDT) Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay03.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2D3A2qx313518 for ; Tue, 12 Mar 2013 23:10:02 -0400 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2D3A04L029424 for ; Wed, 13 Mar 2013 00:10:01 -0300 Received: from jschopp-w520 ([9.80.103.106]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with SMTP id r2D39xhA029294; Wed, 13 Mar 2013 00:09:59 -0300 Received: by jschopp-w520 (Postfix, from userid 1000) id B2CDB501789; Tue, 12 Mar 2013 22:09:55 -0500 (CDT) From: Joel Schopp To: qemu-devel@nongnu.org Date: Tue, 12 Mar 2013 22:09:36 -0500 Message-Id: <1363144182-1016-4-git-send-email-jschopp@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1363144182-1016-1-git-send-email-jschopp@linux.vnet.ibm.com> References: <1363144182-1016-1-git-send-email-jschopp@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13031303-9360-0000-0000-0000114C638E X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 32.97.182.138 Cc: Joel Schopp , Stefan Berger , Michael Tsirkin Subject: [Qemu-devel] [PATCH 3/9] two new file wrappers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Signed-off-by: Stefan Berger Signed-off-by: Joel Schopp --- include/migration/qemu-file.h | 3 +++ qemu-file.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) 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/qemu-file.c b/qemu-file.c index 4fed6d5..f8a54e7 100644 --- a/qemu-file.c +++ b/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; +}