Why not use vsprintf and have a logic to see whether the return bytes are more or less than the buffer size?