From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32838) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ur8DE-00042B-VT for qemu-devel@nongnu.org; Mon, 24 Jun 2013 10:57:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ur8D8-0006ry-Os for qemu-devel@nongnu.org; Mon, 24 Jun 2013 10:57:48 -0400 Received: from e36.co.us.ibm.com ([32.97.110.154]:46391) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ur8D8-0006rr-FP for qemu-devel@nongnu.org; Mon, 24 Jun 2013 10:57:42 -0400 Received: from /spool/local by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 24 Jun 2013 07:46:45 -0600 Received: from d03relay02.boulder.ibm.com (d03relay02.boulder.ibm.com [9.17.195.227]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id D10573E4005E for ; Mon, 24 Jun 2013 07:46:23 -0600 (MDT) Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d03relay02.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r5ODkftB149222 for ; Mon, 24 Jun 2013 07:46:41 -0600 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r5ODkf4Z023418 for ; Mon, 24 Jun 2013 07:46:41 -0600 From: mrhines@linux.vnet.ibm.com Date: Mon, 24 Jun 2013 09:46:21 -0400 Message-Id: <1372081590-24506-6-git-send-email-mrhines@linux.vnet.ibm.com> In-Reply-To: <1372081590-24506-1-git-send-email-mrhines@linux.vnet.ibm.com> References: <1372081590-24506-1-git-send-email-mrhines@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v10 05/14, resend] 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 Reviewed-by: Eric Blake 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 2122bf0..1de6728 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 = g_malloc0(sizeof(QEMUFileSocket)); - 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 = g_malloc0(sizeof(QEMUFileSocket)); + + if (qemu_file_mode_is_not_valid(mode)) { return NULL; } @@ -474,10 +483,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