From 8d33a8a53071865329956fd3a90c196e22338d02 Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Tue, 30 Jun 2009 22:01:03 +1000 Subject: [PATCH] src/common.(c|h) : Add function append_snprintf(). --- src/common.c | 15 +++++++++++++++ src/common.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/common.c b/src/common.c index c444694a..c34c5553 100644 --- a/src/common.c +++ b/src/common.c @@ -1314,6 +1314,21 @@ psf_rand_int32 (void) return value ; } /* psf_rand_int32 */ +void +append_snprintf (char * dest, size_t maxlen, const char * fmt, ...) +{ size_t len = strlen (dest) ; + + if (len < maxlen) + { va_list ap ; + + va_start (ap, fmt) ; + vsnprintf (dest + len, maxlen - len, fmt, ap) ; + va_end (ap) ; + } ; + + return ; +} /* append_snprintf */ + /*============================================================================== */ diff --git a/src/common.h b/src/common.h index f41f96ae..94c5d45a 100644 --- a/src/common.h +++ b/src/common.h @@ -617,6 +617,8 @@ void psf_log_SF_INFO (SF_PRIVATE *psf) ; int32_t psf_rand_int32 (void) ; +void append_snprintf (char * dest, size_t maxlen, const char * fmt, ...) ; + /* Functions used when writing file headers. */ int psf_binheader_writef (SF_PRIVATE *psf, const char *format, ...) ;