From patchwork Thu Mar 21 18:29:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 229795 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 406E02C00AF for ; Fri, 22 Mar 2013 05:30:34 +1100 (EST) Received: from localhost ([::1]:60097 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIkG0-0007bG-Dx for incoming@patchwork.ozlabs.org; Thu, 21 Mar 2013 14:30:32 -0400 Received: from eggs.gnu.org ([208.118.235.92]:37294) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIkFQ-0007K6-AB for qemu-devel@nongnu.org; Thu, 21 Mar 2013 14:30:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UIkFJ-0001fe-2k for qemu-devel@nongnu.org; Thu, 21 Mar 2013 14:29:56 -0400 Received: from e7.ny.us.ibm.com ([32.97.182.137]:39601) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIkFI-0001fG-TT for qemu-devel@nongnu.org; Thu, 21 Mar 2013 14:29:48 -0400 Received: from /spool/local by e7.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 21 Mar 2013 14:29:48 -0400 Received: from d01dlp01.pok.ibm.com (9.56.250.166) by e7.ny.us.ibm.com (192.168.1.107) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 21 Mar 2013 14:29:45 -0400 Received: from d01relay02.pok.ibm.com (d01relay02.pok.ibm.com [9.56.227.234]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id 022FF38C804F for ; Thu, 21 Mar 2013 14:29:45 -0400 (EDT) Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by d01relay02.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r2LITiVK300786 for ; Thu, 21 Mar 2013 14:29:44 -0400 Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r2LIThhV019109 for ; Thu, 21 Mar 2013 14:29:44 -0400 Received: from k-d941f-5.watson.ibm.com (k-d941f-5.watson.ibm.com [9.2.141.165]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r2LIThCJ019084 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 21 Mar 2013 14:29:43 -0400 Received: from k-d941f-5.watson.ibm.com (localhost.localdomain [127.0.0.1]) by k-d941f-5.watson.ibm.com (8.14.5/8.14.3) with ESMTP id r2LITfbp015205; Thu, 21 Mar 2013 14:29:42 -0400 Received: (from root@localhost) by k-d941f-5.watson.ibm.com (8.14.5/8.14.5/Submit) id r2LITfjH015204; Thu, 21 Mar 2013 14:29:41 -0400 From: Stefan Berger To: stefanb@linux.vnet.ibm.com, qemu-devel@nongnu.org, anthony@codemonkey.ws Date: Thu, 21 Mar 2013 14:29:24 -0400 Message-Id: <1363890571-15146-3-git-send-email-stefanb@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1363890571-15146-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1363890571-15146-1-git-send-email-stefanb@linux.vnet.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13032118-5806-0000-0000-0000206E6E76 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 32.97.182.137 Cc: jschopp@linux.vnet.ibm.com, coreyb@linux.vnet.ibm.com, mdroth@linux.vnet.ibm.com, mst@redhat.com Subject: [Qemu-devel] [PATCH v4 2/9] 3 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 3 very short file wrapper functions to make code that follows more readable. Cc: Michael Tsirkin Signed-off-by: Stefan Berger Signed-off-by: Joel Schopp --- 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 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; +}