[pulseaudio-commits] r2434 - in /branches/glitch-free/src/pulsecore: core-util.c core-util.h

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Thu May 15 15:14:46 PDT 2008


Author: lennart
Date: Fri May 16 00:14:45 2008
New Revision: 2434

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=2434&root=pulseaudio&view=rev
Log:
add pa_vsnprintf()

Modified:
    branches/glitch-free/src/pulsecore/core-util.c
    branches/glitch-free/src/pulsecore/core-util.h

Modified: branches/glitch-free/src/pulsecore/core-util.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/glitch-free/src/pulsecore/core-util.c?rev=2434&root=pulseaudio&r1=2433&r2=2434&view=diff
==============================================================================
--- branches/glitch-free/src/pulsecore/core-util.c (original)
+++ branches/glitch-free/src/pulsecore/core-util.c Fri May 16 00:14:45 2008
@@ -1592,12 +1592,28 @@
     pa_assert(format);
 
     va_start(ap, format);
+    ret = pa_vsnprintf(str, size, format, ap);
+    va_end(ap);
+
+    return ret;
+}
+
+/* Same as vsnprintf, but guarantees NUL-termination on every platform */
+int pa_vsnprintf(char *str, size_t size, const char *format, va_list ap) {
+    int ret;
+
+    pa_assert(str);
+    pa_assert(size > 0);
+    pa_assert(format);
+
     ret = vsnprintf(str, size, format, ap);
-    va_end(ap);
 
     str[size-1] = 0;
 
-    return ret;
+    if (ret < 0)
+        ret = strlen(str);
+
+    return PA_MIN((int) size-1, ret);
 }
 
 /* Truncate the specified string, but guarantee that the string

Modified: branches/glitch-free/src/pulsecore/core-util.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/glitch-free/src/pulsecore/core-util.h?rev=2434&root=pulseaudio&r1=2433&r2=2434&view=diff
==============================================================================
--- branches/glitch-free/src/pulsecore/core-util.h (original)
+++ branches/glitch-free/src/pulsecore/core-util.h Fri May 16 00:14:45 2008
@@ -128,6 +128,7 @@
 int pa_atof(const char *s, float *ret_f);
 
 int pa_snprintf(char *str, size_t size, const char *format, ...);
+int pa_vsnprintf(char *str, size_t size, const char *format, va_list ap);
 
 char *pa_truncate_utf8(char *c, size_t l);
 




More information about the pulseaudio-commits mailing list