Erm, sorry, I misread the docs there. It does not return how much you need to allocate.

In cases like this, the usual thing to do is to keep doubling the buffer's length until it's large enough to fit the data.