Added a simple implementation of vsnprintf for unix platforms

without it using /dev/null, vfprintf(), and vsprintf().
This commit is contained in:
crs 2003-02-12 19:50:22 +00:00
parent 154a474289
commit fefe457517
1 changed files with 27 additions and 1 deletions

View File

@ -28,7 +28,33 @@ ARCH_STRING::vsnprintf(char* str, int size, const char* fmt, va_list ap)
return n; return n;
} }
#else // !HAVE_VSNPRINTF #elif UNIX_LIKE // !HAVE_VSNPRINTF
#include <stdio.h>
int
ARCH_STRING::vsnprintf(char* str, int size, const char* fmt, va_list ap)
{
static FILE* bitbucket = fopen("/dev/null", "w");
if (bitbucket == NULL) {
// uh oh
if (size > 0) {
str[0] = '\0';
}
return 0;
}
else {
// count the characters using the bitbucket
int n = vfprintf(bitbucket, fmt, ap);
if (n + 1 <= size) {
// it'll fit so print it into str
vsprintf(str, fmt, ap);
}
return n;
}
}
#else // !HAVE_VSNPRINTF && !UNIX_LIKE
// FIXME // FIXME
#error vsnprintf not implemented #error vsnprintf not implemented