Yeah, I originally had this as a call to asprintf which formats into an allocated buffer of the correct length. However, I think that is less portable.