]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/strbuf.c
Fix up according to Coding Style
[pulseaudio] / src / pulsecore / strbuf.c
index 7c576c672d4685eeeb3b010652bc82ead350640d..f131d5cdbb0f330208f0f6b7ba32bb7997038f3c 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id$ */
-
 /***
   This file is part of PulseAudio.
 
@@ -7,7 +5,7 @@
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
-  by the Free Software Foundation; either version 2 of the License,
+  by the Free Software Foundation; either version 2.1 of the License,
   or (at your option) any later version.
 
   PulseAudio is distributed in the hope that it will be useful, but
@@ -79,7 +77,7 @@ char *pa_strbuf_tostring(pa_strbuf *sb) {
 
     pa_assert(sb);
 
-    e = t = pa_xnew(char, sb->length+1);
+    e = t = pa_xmalloc(sb->length+1);
 
     for (c = sb->head; c; c = c->next) {
         pa_assert((size_t) (e-t) <= sb->length);
@@ -115,6 +113,13 @@ void pa_strbuf_puts(pa_strbuf *sb, const char *t) {
     pa_strbuf_putsn(sb, t, strlen(t));
 }
 
+/* Append a character to the string buffer */
+void pa_strbuf_putc(pa_strbuf *sb, char c) {
+    pa_assert(sb);
+
+    pa_strbuf_putsn(sb, &c, 1);
+}
+
 /* Append a new chunk to the linked list */
 static void append(pa_strbuf *sb, struct chunk *c) {
     pa_assert(sb);
@@ -141,7 +146,7 @@ void pa_strbuf_putsn(pa_strbuf *sb, const char *t, size_t l) {
     pa_assert(t);
 
     if (!l)
-       return;
+        return;
 
     c = pa_xmalloc(PA_ALIGN(sizeof(struct chunk)) + l);
     c->length = l;
@@ -152,8 +157,8 @@ void pa_strbuf_putsn(pa_strbuf *sb, const char *t, size_t l) {
 
 /* Append a printf() style formatted string to the string buffer. */
 /* The following is based on an example from the GNU libc documentation */
-int pa_strbuf_printf(pa_strbuf *sb, const char *format, ...) {
-    int size = 100;
+size_t pa_strbuf_printf(pa_strbuf *sb, const char *format, ...) {
+    size_t size = 100;
     struct chunk *c = NULL;
 
     pa_assert(sb);
@@ -170,15 +175,21 @@ int pa_strbuf_printf(pa_strbuf *sb, const char *format, ...) {
         CHUNK_TO_TEXT(c)[size-1] = 0;
         va_end(ap);
 
-        if (r > -1 && r < size) {
-            c->length = r;
+        if (r > -1 && (size_t) r < size) {
+            c->length = (size_t) r;
             append(sb, c);
-            return r;
+            return (size_t) r;
         }
 
         if (r > -1)    /* glibc 2.1 */
-            size = r+1;
+            size = (size_t) r+1;
         else           /* glibc 2.0 */
             size *= 2;
     }
 }
+
+pa_bool_t pa_strbuf_isempty(pa_strbuf *sb) {
+    pa_assert(sb);
+
+    return sb->length <= 0;
+}