aboutsummaryrefslogtreecommitdiff
path: root/qstring.c
diff options
context:
space:
mode:
authorLuiz Capitulino <lcapitulino@redhat.com>2009-11-18 23:05:25 -0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-12-03 09:41:19 -0600
commit6fe9565c5b6f2872f115223df3d8d61eb78bff8c (patch)
tree78aa973fbcc7997de5996d609b76377169831f53 /qstring.c
parent8ff5a7d346b932fbae49d08d8824d0cc15c3ed3c (diff)
QString: Introduce qstring_append_chr()
It appends a C char to a QString. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'qstring.c')
-rw-r--r--qstring.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/qstring.c b/qstring.c
index 441a9e6ef0..e422bd952d 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)