From 2380ad9254a410235869b18c523787071e2a71d4 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 25 Jul 2007 15:49:35 +0000 Subject: [PATCH] add our own implementation for pa_snprintf() because NUL termination is apparently not guaranteed on windows and a couple of other libcs git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1531 fefdeb5f-60dc-0310-8127-8f9354f1896f --- src/pulsecore/core-util.c | 20 +++++++++++++++++++- src/pulsecore/core-util.h | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index e5766b2..9879048 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -83,6 +82,7 @@ #include #include #include +#include #include "core-util.h" @@ -1202,3 +1202,21 @@ int pa_atou(const char *s, uint32_t *ret_u) { return 0; } + +/* Same as snprintf, but guarantees NUL-termination on every platform */ +int pa_snprintf(char *str, size_t size, const char *format, ...) { + int ret; + va_list ap; + + pa_assert(str); + pa_assert(size > 0); + pa_assert(format); + + va_start(ap, format); + ret = vsnprintf(str, size, format, ap); + va_end(ap); + + str[size-1] = 0; + + return ret; +} diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h index 1d921e0..a593317 100644 --- a/src/pulsecore/core-util.h +++ b/src/pulsecore/core-util.h @@ -92,4 +92,6 @@ char *pa_runtime_path(const char *fn, char *s, size_t l); int pa_atoi(const char *s, int32_t *ret_i); int pa_atou(const char *s, uint32_t *ret_u); +int pa_snprintf(char *str, size_t size, const char *format, ...); + #endif -- 2.7.4