When using standard char*
strings, the snprintf
and vsnprintf
functions will return the length of the output string, even if that string was truncated due to overflow.* It seems like the ISO C committee didn't like this functionality when they added swprintf
and vswprintf
, which return -1 on overflow.
Does anyone know of a function that will provide this length? I don't know the size of the potential strings. I might be asking too much, but.. I'd rather not:
- allocate a huge static temp buffer
- iteratively allocate and free memory until i've found a size that fits
- add an additional library dependency
- write my own format string parser
*I realize MSVC doesn't do this, and instead provides the scprintf
and vscprintf
functions, but I'm looking for other compilers, mainly GCC.