From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44294) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UrIWO-0001lQ-7H for qemu-devel@nongnu.org; Mon, 24 Jun 2013 21:58:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UrIWL-000186-E4 for qemu-devel@nongnu.org; Mon, 24 Jun 2013 21:58:16 -0400 Received: from e9.ny.us.ibm.com ([32.97.182.139]:45900) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UrIWL-00017x-AN for qemu-devel@nongnu.org; Mon, 24 Jun 2013 21:58:13 -0400 Received: from /spool/local by e9.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 24 Jun 2013 21:58:12 -0400 Received: from d01relay03.pok.ibm.com (d01relay03.pok.ibm.com [9.56.227.235]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id E350038C8065 for ; Mon, 24 Jun 2013 21:58:09 -0400 (EDT) Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay03.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r5P1wAon282230 for ; Mon, 24 Jun 2013 21:58:10 -0400 Received: from d01av03.pok.ibm.com (loopback [127.0.0.1]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r5P1w90T029201 for ; Mon, 24 Jun 2013 22:58:10 -0300 From: mrhines@linux.vnet.ibm.com Date: Mon, 24 Jun 2013 21:57:55 -0400 Message-Id: <1372125485-11795-6-git-send-email-mrhines@linux.vnet.ibm.com> In-Reply-To: <1372125485-11795-1-git-send-email-mrhines@linux.vnet.ibm.com> References: <1372125485-11795-1-git-send-email-mrhines@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v11 05/15] rdma: introduce qemu_file_mode_is_not_valid() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, quintela@redhat.com, knoel@redhat.com, owasserm@redhat.com, abali@us.ibm.com, mrhines@us.ibm.com, gokul@us.ibm.com, pbonzini@redhat.com, chegu_vinod@hp.com From: "Michael R. Hines" QEMUFileRDMA also has read and write modes. This function is now shared to reduce code duplication. Reviewed-by: Paolo Bonzini Reviewed-by: Chegu Vinod Tested-by: Chegu Vinod Tested-by: Michael R. Hines Signed-off-by: Michael R. Hines --- include/migration/qemu-file.h | 1 + savevm.c | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h index 8fab0dd..dd3fd51 100644 --- a/include/migration/qemu-file.h +++ b/include/migration/qemu-file.h @@ -80,6 +80,7 @@ void qemu_put_byte(QEMUFile *f, int v); * The buffer should be available till it is sent asynchronously. */ void qemu_put_buffer_async(QEMUFile *f, const uint8_t *buf, int size); +bool qemu_file_mode_is_not_valid(const char *mode); static inline void qemu_put_ubyte(QEMUFile *f, unsigned int v) { diff --git a/savevm.c b/savevm.c index e35c7a4..67ddf06 100644 --- a/savevm.c +++ b/savevm.c @@ -449,14 +449,23 @@ static const QEMUFileOps socket_write_ops = { .close = socket_close }; -QEMUFile *qemu_fopen_socket(int fd, const char *mode) +bool qemu_file_mode_is_not_valid(const char *mode) { - QEMUFileSocket *s; - if (mode == NULL || (mode[0] != 'r' && mode[0] != 'w') || mode[1] != 'b' || mode[2] != 0) { fprintf(stderr, "qemu_fopen: Argument validity check failed\n"); + return true; + } + + return false; +} + +QEMUFile *qemu_fopen_socket(int fd, const char *mode) +{ + QEMUFileSocket *s; + + if (qemu_file_mode_is_not_valid(mode)) { return NULL; } @@ -475,10 +484,7 @@ QEMUFile *qemu_fopen(const char *filename, const char *mode) { QEMUFileStdio *s; - if (mode == NULL || - (mode[0] != 'r' && mode[0] != 'w') || - mode[1] != 'b' || mode[2] != 0) { - fprintf(stderr, "qemu_fopen: Argument validity check failed\n"); + if (qemu_file_mode_is_not_valid(mode)) { return NULL; } -- 1.7.10.4