SimpleString VStringFromFormat(const char* format, va_list args) { va_list argsCopy; va_copy(argsCopy, args); enum { sizeOfdefaultBuffer = 100 }; char defaultBuffer[sizeOfdefaultBuffer]; SimpleString resultString; size_t size = (size_t)PlatformSpecificVSNprintf(defaultBuffer, sizeOfdefaultBuffer, format, args); if (size < sizeOfdefaultBuffer) { resultString = SimpleString(defaultBuffer); } else { size_t newBufferSize = size + 1; char* newBuffer = SimpleString::allocStringBuffer(newBufferSize, __FILE__, __LINE__); PlatformSpecificVSNprintf(newBuffer, newBufferSize, format, argsCopy); resultString = SimpleString(newBuffer); SimpleString::deallocStringBuffer(newBuffer, __FILE__, __LINE__); } va_end(argsCopy); return resultString; }
SimpleString VStringFromFormat(const char* format, va_list args) { va_list argsCopy; va_copy(argsCopy, args); enum { sizeOfdefaultBuffer = 100 }; char defaultBuffer[sizeOfdefaultBuffer]; SimpleString resultString; int size = PlatformSpecificVSNprintf(defaultBuffer, sizeOfdefaultBuffer, format, args); if (size < sizeOfdefaultBuffer) { resultString = SimpleString(defaultBuffer); } else { char* newBuffer = new char[size + 1]; PlatformSpecificVSNprintf(newBuffer, size + 1, format, argsCopy); resultString = SimpleString(newBuffer); delete[] newBuffer; } return resultString; }
int printk (const char * fmt, ...) { va_list args; SimpleString::StrNCpy(log_level, fmt, 2); fmt += 2; va_start(args, fmt); return PlatformSpecificVSNprintf(log_buffer, NBUF, fmt, args); }
static int WrappedUpVSNPrintf(char* buf, size_t n, const char* format, ...) { va_list arguments; va_start(arguments, format); int result = PlatformSpecificVSNprintf(buf, n, format, arguments); va_end(arguments); return result; }
void SimpleStringBuffer::add(const char* format, ...) { int count = 0; size_t positions_left = write_limit_ - positions_filled_; if (positions_left <= 0) return; va_list arguments; va_start(arguments, format); count = PlatformSpecificVSNprintf(buffer_ + positions_filled_, positions_left+1, format, arguments); if (count > 0) positions_filled_ += (size_t) count; if (positions_filled_ > write_limit_) positions_filled_ = write_limit_; va_end(arguments); }