Juan Lang wrote:
snprintf always writes terminating '\0' character at the end of the string.
Only if the buffer contains enough space for the terminating null.
No (in case buffer at least 1 byte long). From man page:
The functions snprintf() and vsnprintf() write at most size bytes (including the trailing null byte ('\0')) to str.
This means that terminating zero is always written to the buffer (if it's at least 1 char long). I agree that above part of the man page is not exactly clear. But you can find a better explanation on the web, which spell out what is actually written.
This is not the infamous strncpy that does what you said.
Vitaliy.