diff options
author | Lennart Poettering <lennart@poettering.net> | 2008-05-15 22:14:45 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2008-05-15 22:14:45 +0000 |
commit | b57c520149e12339417813cbee07442ccbc788f7 (patch) | |
tree | a83c87b541e449ee1e7424a72f7526d810951548 | |
parent | 1a2e5a8a8026a40ab351901216ffe8dcb173cfdb (diff) |
add pa_vsnprintf()
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/glitch-free@2434 fefdeb5f-60dc-0310-8127-8f9354f1896f
-rw-r--r-- | src/pulsecore/core-util.c | 20 | ||||
-rw-r--r-- | src/pulsecore/core-util.h | 1 |
2 files changed, 19 insertions, 2 deletions
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index df110966..c8ea4f52 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -1592,12 +1592,28 @@ int pa_snprintf(char *str, size_t size, const char *format, ...) { pa_assert(format); va_start(ap, format); - ret = vsnprintf(str, size, format, ap); + 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); + 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 diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h index e9313d4b..ec4cdc43 100644 --- a/src/pulsecore/core-util.h +++ b/src/pulsecore/core-util.h @@ -128,6 +128,7 @@ int pa_atou(const char *s, uint32_t *ret_u); 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); |