More fixes for varargs stuff

But still no luck on Android
This commit is contained in:
Andrew Bettison 2012-05-23 16:07:52 +09:30
parent 1af9125392
commit 59e58da2f4
4 changed files with 19 additions and 28 deletions

View File

@ -359,25 +359,29 @@ int cli_puts(const char *str)
int cli_printf(const char *fmt, ...)
{
int ret = 0;
va_list ap,ap2;
va_start(ap,fmt);
va_copy(ap2,ap);
va_list ap;
#ifdef HAVE_JNI_H
if (jni_env) {
size_t avail = outv_limit - outv_current;
int count = vsnprintf(outv_current, avail, fmt, ap2);
va_start(ap, fmt);
int count = vsnprintf(outv_current, avail, fmt, ap);
va_end(ap);
if (count >= avail) {
if (outv_growbuf(count) == -1)
return -1;
vsprintf(outv_current, fmt, ap2);
va_start(ap, fmt);
vsprintf(outv_current, fmt, ap);
va_end(ap);
}
outv_current += count;
ret = count;
} else
#endif
ret = vfprintf(stdout, fmt, ap2);
va_end(ap2);
va_end(ap);
{
va_start(ap, fmt);
ret = vfprintf(stdout, fmt, ap);
va_end(ap);
}
return ret;
}

5
log.c
View File

@ -37,11 +37,8 @@ void logMessage(int level, char *fmt, ...)
void vlogMessage(int level, char *fmt, va_list ap)
{
va_list ap2;
char buf[8192];
va_copy(ap2, ap);
vsnprintf(buf, sizeof buf, fmt, ap2);
va_end(ap2);
vsnprintf(buf, sizeof buf, fmt, ap);
buf[sizeof buf - 1] = '\0';
#ifdef ANDROID
int alevel = ANDROID_LOG_UNKNOWN;

View File

@ -61,10 +61,7 @@ int form_rhizome_datastore_path(char * buf, size_t bufsiz, const char *fmt, ...)
strbuf_sprintf(b, "%s/", rhizome_datastore_path());
va_list ap;
va_start(ap, fmt);
va_list ap2;
va_copy(ap2, ap);
strbuf_sprintf(b, fmt, ap2);
va_end(ap2);
strbuf_sprintf(b, fmt, ap);
va_end(ap);
if (strbuf_overrun(b)) {
WHY("Path buffer overrun");
@ -151,15 +148,11 @@ long long sqlite_exec_int64(char *sqlformat,...)
{
if (!rhizome_db) rhizome_opendb();
va_list ap,ap2;
char sqlstatement[8192];
va_start(ap,sqlformat);
va_copy(ap2,ap);
vsnprintf(sqlstatement,8192,sqlformat,ap2); sqlstatement[8191]=0;
va_end(ap2);
va_list ap;
va_start(ap, sqlformat);
vsnprintf(sqlstatement,8192,sqlformat,ap); sqlstatement[8191]=0;
va_end(ap);
sqlite3_stmt *statement;

View File

@ -75,19 +75,16 @@ int strbuf_sprintf(strbuf sb, const char *fmt, ...)
int strbuf_vsprintf(strbuf sb, const char *fmt, va_list ap)
{
va_list ap2;
va_copy(ap2, ap);
int n;
if (sb->start && sb->current < sb->end) {
n = vsnprintf(sb->current, sb->end - sb->current + 1, fmt, ap2);
n = vsnprintf(sb->current, sb->end - sb->current + 1, fmt, ap);
*sb->end = '\0';
} else {
char tmp[1];
n = vsnprintf(tmp, sizeof tmp, fmt, ap2);
n = vsnprintf(tmp, sizeof tmp, fmt, ap);
}
if (n != -1)
sb->current += n;
va_end(ap2);
return n;
}