1
0
mirror of https://github.com/signalwire/freeswitch.git synced 2025-08-13 01:26:58 +00:00
Files
build
clients
cmake_modules
conf
debian
docs
dtd
freeswitch.xcodeproj
fscomm
htdocs
libs
apr
apr-util
broadvoice
curl
esl
freetdm
iksemel
ilbc
js
ldns
libcodec2
libdingaling
libedit
libg722_1
libnatpmp
libscgi
libsndfile
libteletone
libzrtp
miniupnpc
openzap
pcre
portaudio
silk
sofia-sip
spandsp
speex
sqlite
srtp
stfu
tiff-3.8.2
unimrcp
win32
xmlrpc-c
Windows
conf
debian
doc
examples
include
lib
abyss
curl_transport
expat
libutil
libwww_transport
util
include
Makefile
Makefile.depend
casprintf.c
cmdline_parser.c
cmdline_parser_cpp.cpp
getoptx.c
getoptx.h
pthreadx_win32.c
string_parser.c
stripcaseeq.c
wininet_transport
Makefile
Makefile.depend
src
tools
.cvsignore
.update
GNUmakefile
Makefile
Makefile.common
Makefile.config.in
Makefile.depend
Makefile.srcdir.in
Makefile.version
README
common.mk
config.mk.in
configure.gnu
configure.in
dll-common.make
dylib-common.make
install-sh
irix-common.make
ltconfig
missing
mkinstalldirs
stamp-h.in
transport_config.make
unix-common.make
version.h
xmlrpc-c-config.in
xmlrpc-c-config.main
xmlrpc-c-config.test.in
xmlrpc-c-config.test.main
xmlrpc_amconfig.h.in
xmlrpc_config.h.in
yaml
.gitignore
patches
scripts
src
support-d
w32
web
.gitattributes
.gitignore
CMakeLists.txt
Freeswitch.2005.unsupported.sln
Freeswitch.2008.express.sln
Freeswitch.2008.sln
Freeswitch.2008.sln.debug.bat
Freeswitch.2008.sln.release.bat
Freeswitch.2010.express.sln
Freeswitch.2010.sln
INSTALL
Makefile.am
acinclude.m4
bootstrap.sh
cc.sh
cluecon.tmpl
configure.in
devel-bootstrap.sh
erlang.spec
freeswitch-sounds-en-us-callie.spec
freeswitch-sounds-music.spec
freeswitch-sounds-ru-RU-elena.spec
freeswitch.spec
swig_common.i
freeswitch/libs/xmlrpc-c/lib/util/casprintf.c
2008-05-23 22:54:19 +00:00

94 lines
2.4 KiB
C

//#define _GNU_SOURCE
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "xmlrpc_config.h" /* For HAVE_ASPRINTF, __inline__ */
#include "casprintf.h"
static __inline__ void
simpleVasprintf(char ** const retvalP,
const char * const fmt,
va_list varargs) {
/*----------------------------------------------------------------------------
This is a poor man's implementation of vasprintf(), of GNU fame.
-----------------------------------------------------------------------------*/
size_t const initialSize = 4096;
char * result;
result = malloc(initialSize);
if (result != NULL) {
size_t bytesNeeded;
bytesNeeded = XMLRPC_VSNPRINTF(result, initialSize, fmt, varargs);
if (bytesNeeded > initialSize) {
free(result);
result = malloc(bytesNeeded);
if (result != NULL)
XMLRPC_VSNPRINTF(result, bytesNeeded, fmt, varargs);
} else if (bytesNeeded == initialSize) {
if (result[initialSize-1] != '\0') {
/* This is one of those old systems where vsnprintf()
returns the number of bytes it used, instead of the
number that it needed, and it in fact needed more than
we gave it. Rather than mess with this highly unlikely
case (old system and string > 4095 characters), we just
treat this like an out of memory failure.
*/
free(result);
result = NULL;
}
}
}
*retvalP = result;
}
const char * const strsol = "[Insufficient memory to build string]";
void
cvasprintf(const char ** const retvalP,
const char * const fmt,
va_list varargs) {
char * string;
#if HAVE_ASPRINTF
vasprintf(&string, fmt, varargs);
#else
simpleVasprintf(&string, fmt, varargs);
#endif
if (string == NULL)
*retvalP = strsol;
else
*retvalP = string;
}
void GNU_PRINTF_ATTR(2,3)
casprintf(const char ** const retvalP, const char * const fmt, ...) {
va_list varargs; /* mysterious structure used by variable arg facility */
va_start(varargs, fmt); /* start up the mysterious variable arg facility */
cvasprintf(retvalP, fmt, varargs);
va_end(varargs);
}
void
strfree(const char * const string) {
if (string != strsol)
free((void *)string);
}