]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/strbuf.c
core-util: ensure that we chmod only the dir we ourselves created
[pulseaudio] / src / pulsecore / strbuf.c
index b59b6f495b305e797af86c413c6cc629657824e9..4fc82ded2ee5ff02c6e87ef65cd0fac2e9f247fa 100644 (file)
@@ -5,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
 
   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
   or (at your option) any later version.
 
   PulseAudio is distributed in the hope that it will be useful, but
@@ -77,7 +77,7 @@ char *pa_strbuf_tostring(pa_strbuf *sb) {
 
     pa_assert(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);
 
     for (c = sb->head; c; c = c->next) {
         pa_assert((size_t) (e-t) <= sb->length);
@@ -113,6 +113,13 @@ void pa_strbuf_puts(pa_strbuf *sb, const char *t) {
     pa_strbuf_putsn(sb, t, strlen(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);
 /* Append a new chunk to the linked list */
 static void append(pa_strbuf *sb, struct chunk *c) {
     pa_assert(sb);
@@ -150,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 */
 
 /* 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);
     struct chunk *c = NULL;
 
     pa_assert(sb);
@@ -168,15 +175,21 @@ int pa_strbuf_printf(pa_strbuf *sb, const char *format, ...) {
         CHUNK_TO_TEXT(c)[size-1] = 0;
         va_end(ap);
 
         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);
             append(sb, c);
-            return r;
+            return (size_t) r;
         }
 
         if (r > -1)    /* glibc 2.1 */
         }
 
         if (r > -1)    /* glibc 2.1 */
-            size = r+1;
+            size = (size_t) r+1;
         else           /* glibc 2.0 */
             size *= 2;
     }
 }
         else           /* glibc 2.0 */
             size *= 2;
     }
 }
+
+pa_bool_t pa_strbuf_isempty(pa_strbuf *sb) {
+    pa_assert(sb);
+
+    return sb->length <= 0;
+}