Not sure offhand how portable it is, but asprintf() handles automatic buffer allocation, thus not requiring any extra steps afaik.
It does exit on MacOS and Linux, at the very least.
It does exit on MacOS and Linux, at the very least.
But my man pages say that they exist on BSD in addition to GNU, so that’s pretty good these days. I say go for it.