mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 04:11:08 +00:00
add ast_build_string library function (from bug #3644)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5684 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
23
utils.c
23
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)
|
||||
|
Reference in New Issue
Block a user