aboutsummaryrefslogtreecommitdiffstats
path: root/utils.c
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-05-15 22:33:02 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-05-15 22:33:02 +0000
commitf196d285a3a25a99b1dfcab391779ca047364e45 (patch)
tree57e238c52aa2a0479fb069df9351ed3ef2f4fdf3 /utils.c
parentd2478e8f4ff36fb7c548d96868d8803913152e39 (diff)
add ast_build_string library function (from bug #3644)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5684 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'utils.c')
-rwxr-xr-xutils.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/utils.c b/utils.c
index 5264ecc05..594ef6e7b 100755
--- a/utils.c
+++ b/utils.c
@@ -17,6 +17,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
+#include <stdarg.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
@@ -433,6 +434,28 @@ void ast_copy_string(char *dst, const char *src, size_t size)
*dst = '\0';
}
+int ast_build_string(char **buffer, size_t *space, const char *fmt, ...)
+{
+ va_list ap;
+ int result;
+
+ if (!buffer || !*buffer || !space || !*space)
+ return -1;
+
+ va_start(ap, fmt);
+ result = vsnprintf(*buffer, *space, fmt, ap);
+ va_end(ap);
+
+ if (result < 0)
+ return -1;
+ else if (result > *space)
+ result = *space;
+
+ *buffer += result;
+ *space -= result;
+ return 0;
+}
+
/* Case-insensitive substring matching */
#ifndef LINUX
static char *upper(const char *orig, char *buf, int bufsize)