From patchwork Thu Nov 19 01:05:27 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 38799 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 898C4B6F04 for ; Thu, 19 Nov 2009 12:12:12 +1100 (EST) Received: from localhost ([127.0.0.1]:49428 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NAvZB-0005Wx-KU for incoming@patchwork.ozlabs.org; Wed, 18 Nov 2009 20:12:09 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NAvTO-0003GP-Mi for qemu-devel@nongnu.org; Wed, 18 Nov 2009 20:06:10 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NAvTJ-0003DV-4Q for qemu-devel@nongnu.org; Wed, 18 Nov 2009 20:06:09 -0500 Received: from [199.232.76.173] (port=35029 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NAvTI-0003DH-Tg for qemu-devel@nongnu.org; Wed, 18 Nov 2009 20:06:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:61371) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NAvTI-0008Bf-5J for qemu-devel@nongnu.org; Wed, 18 Nov 2009 20:06:04 -0500 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAJ163V9026764 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 18 Nov 2009 20:06:03 -0500 Received: from localhost (vpn-11-188.rdu.redhat.com [10.11.11.188]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nAJ161fD006475; Wed, 18 Nov 2009 20:06:02 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Wed, 18 Nov 2009 23:05:27 -0200 Message-Id: <1258592736-10252-5-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1258592736-10252-1-git-send-email-lcapitulino@redhat.com> References: <1258592736-10252-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com, kraxel@redhat.com, armbru@redhat.com Subject: [Qemu-devel] [PATCH 04/13] QString: Introduce qstring_from_substr() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Note that we can now write qstring_from_str() as a wrapper. Signed-off-by: Luiz Capitulino --- qstring.c | 20 +++++++++++++++----- qstring.h | 1 + 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/qstring.c b/qstring.c index ad17769..740a106 100644 --- a/qstring.c +++ b/qstring.c @@ -31,21 +31,21 @@ QString *qstring_new(void) } /** - * qstring_from_str(): Create a new QString from a regular C string + * qstring_from_substr(): Create a new QString from a C string substring * - * Return strong reference. + * Return string reference */ -QString *qstring_from_str(const char *str) +QString *qstring_from_substr(const char *str, int start, int end) { QString *qstring; qstring = qemu_malloc(sizeof(*qstring)); - qstring->length = strlen(str); + qstring->length = end - start + 1; qstring->capacity = qstring->length; qstring->string = qemu_malloc(qstring->capacity + 1); - memcpy(qstring->string, str, qstring->length); + memcpy(qstring->string, str + start, qstring->length); qstring->string[qstring->length] = 0; QOBJECT_INIT(qstring, &qstring_type); @@ -53,6 +53,16 @@ QString *qstring_from_str(const char *str) return qstring; } +/** + * qstring_from_str(): Create a new QString from a regular C string + * + * Return strong reference. + */ +QString *qstring_from_str(const char *str) +{ + return qstring_from_substr(str, 0, strlen(str) - 1); +} + static void capacity_increase(QString *qstring, size_t len) { if (qstring->capacity < (qstring->length + len)) { diff --git a/qstring.h b/qstring.h index c065331..6aaa7d5 100644 --- a/qstring.h +++ b/qstring.h @@ -13,6 +13,7 @@ typedef struct QString { QString *qstring_new(void); QString *qstring_from_str(const char *str); +QString *qstring_from_substr(const char *str, int start, int end); const char *qstring_get_str(const QString *qstring); void qstring_append_int(QString *qstring, int64_t value); void qstring_append(QString *qstring, const char *str);