From 49b620d06a9b5c835e97aa238b42d5d56743e6fb Mon Sep 17 00:00:00 2001 From: FlavioJS Date: Wed, 6 Dec 2006 04:25:13 +0000 Subject: - Added StringBuf_Vprintf to utils.c and changed the showmsg.c buffer. Now it uses a static buffer and a StringBuf when needed (a debug message indicating the static buffer needs to be increased is shown). git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@9414 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/common/utils.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/common/utils.c') diff --git a/src/common/utils.c b/src/common/utils.c index 3172e89d9..c7b3b517a 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -155,18 +155,15 @@ void StringBuf_Init(struct StringBuf * sbuf) { sbuf->ptr_ = sbuf->buf_ = (char *) aMallocA(sbuf->max_ + 1); } -// printf into a StringBuf, moving the pointer [MouseJstr] -int StringBuf_Printf(struct StringBuf *sbuf,const char *fmt,...) +// vprintf into a StringBuf, moving the pointer [MouseJstr] +int StringBuf_Vprintf(struct StringBuf *sbuf,const char *fmt,va_list ap) { - va_list ap; - int n, size, off; + int n, size, off; while (1) { /* Try to print in the allocated space. */ - va_start(ap, fmt); size = sbuf->max_ - (sbuf->ptr_ - sbuf->buf_); n = vsnprintf (sbuf->ptr_, size, fmt, ap); - va_end(ap); /* If that worked, return the length. */ if (n > -1 && n < size) { sbuf->ptr_ += n; @@ -180,6 +177,19 @@ int StringBuf_Printf(struct StringBuf *sbuf,const char *fmt,...) } } +// printf into a StringBuf, moving the pointer [MouseJstr] +int StringBuf_Printf(struct StringBuf *sbuf,const char *fmt,...) +{ + int len; + va_list ap; + + va_start(ap,fmt); + len = StringBuf_Vprintf(sbuf,fmt,ap); + va_end(ap); + + return len; +} + // Append buf2 onto the end of buf1 [MouseJstr] int StringBuf_Append(struct StringBuf *buf1,const struct StringBuf *buf2) { -- cgit v1.2.3-60-g2f50