mirror of
https://github.com/debauchee/barrier.git
synced 2024-11-27 10:38:48 +03:00
Added a simple implementation of vsnprintf for unix platforms
without it using /dev/null, vfprintf(), and vsprintf().
This commit is contained in:
parent
154a474289
commit
fefe457517
@ -28,7 +28,33 @@ ARCH_STRING::vsnprintf(char* str, int size, const char* fmt, va_list ap)
|
||||
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
|
||||
#error vsnprintf not implemented
|
||||
|
Loading…
Reference in New Issue
Block a user