From patchwork Thu Nov 19 01:05:25 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 38797 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 3B4BA1007D1 for ; Thu, 19 Nov 2009 12:09:25 +1100 (EST) Received: from localhost ([127.0.0.1]:32854 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NAvWU-0004WZ-Hs for incoming@patchwork.ozlabs.org; Wed, 18 Nov 2009 20:09:22 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NAvTJ-0003Dk-SK for qemu-devel@nongnu.org; Wed, 18 Nov 2009 20:06:05 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NAvTE-0003Bf-AF for qemu-devel@nongnu.org; Wed, 18 Nov 2009 20:06:04 -0500 Received: from [199.232.76.173] (port=35027 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NAvTE-0003Bc-51 for qemu-devel@nongnu.org; Wed, 18 Nov 2009 20:06:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:5188) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NAvTD-0008B7-Iu for qemu-devel@nongnu.org; Wed, 18 Nov 2009 20:05:59 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAJ15wWO006283 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 18 Nov 2009 20:05:59 -0500 Received: from localhost (vpn-11-188.rdu.redhat.com [10.11.11.188]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nAJ15v13022524; Wed, 18 Nov 2009 20:05:58 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Wed, 18 Nov 2009 23:05:25 -0200 Message-Id: <1258592736-10252-3-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.11 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 02/13] QString: Introduce qstring_append_chr() 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 It appends a C char to a QString. Signed-off-by: Luiz Capitulino --- qstring.c | 24 +++++++++++++++++++----- qstring.h | 1 + 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/qstring.c b/qstring.c index 441a9e6..e422bd9 100644 --- a/qstring.c +++ b/qstring.c @@ -53,25 +53,39 @@ QString *qstring_from_str(const char *str) return qstring; } -/* qstring_append(): Append a C string to a QString - */ -void qstring_append(QString *qstring, const char *str) +static void capacity_increase(QString *qstring, size_t len) { - size_t len = strlen(str); - if (qstring->capacity < (qstring->length + len)) { qstring->capacity += len; qstring->capacity *= 2; /* use exponential growth */ qstring->string = qemu_realloc(qstring->string, qstring->capacity + 1); } +} + +/* qstring_append(): Append a C string to a QString + */ +void qstring_append(QString *qstring, const char *str) +{ + size_t len = strlen(str); + capacity_increase(qstring, len); memcpy(qstring->string + qstring->length, str, len); qstring->length += len; qstring->string[qstring->length] = 0; } /** + * qstring_append_chr(): Append a C char to a QString + */ +void qstring_append_chr(QString *qstring, int c) +{ + capacity_increase(qstring, 1); + qstring->string[qstring->length++] = c; + qstring->string[qstring->length] = 0; +} + +/** * qobject_to_qstring(): Convert a QObject to a QString */ QString *qobject_to_qstring(const QObject *obj) diff --git a/qstring.h b/qstring.h index 65905d4..43581de 100644 --- a/qstring.h +++ b/qstring.h @@ -14,6 +14,7 @@ QString *qstring_new(void); QString *qstring_from_str(const char *str); const char *qstring_get_str(const QString *qstring); void qstring_append(QString *qstring, const char *str); +void qstring_append_chr(QString *qstring, int c); QString *qobject_to_qstring(const QObject *obj); #endif /* QSTRING_H */