Alejandro Colomar wrote:
> I think asprintf(3) is unnecessarily complex. It might be an
> interesting optimized API for a niche use case, but not something the
> average programmer should care about
+1
And the performance considerations of running strlen() on a string are part
of the choice of the string representation ('char *' with NUL terminator)
of C. The *normal* way to represent / return strings in C is as a 'char *',
and whoever needs the length later needs to run strlen().
Anyone who wants to avoid calls to strlen(), and also allow the use of
embedded NUL characters, should use the Gnulib <string-desc.h> facility [1].
So far, it does not have a printf-like operation; but I can add one if
you feel that would be useful.
Bruno
[1]
https://www.gnu.org/software/gnulib/manual/html_node/Handling-strings-with-NUL-characters.html