That man page says:

CONFORMING TO
       These functions are GNU extensions, not in C or POSIX.  They  are  also
       available  under *BSD.  The FreeBSD implementation sets strp to NULL on
       error.

So not sure how portable that is. I think this is why PHP has it's own 
spprintf. asprintf also doesn't have a limit to the string length, which 
is a bit scary. 

Another alternative would be smart_str, but that doesn't have a great 
API.

Let's keep it as you had!