Sujet : Re: FreeTDS port to VMS V9.x on x86?
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.os.vmsDate : 24. Jun 2025, 02:41:18
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <103cvnu$1jvc7$5@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
User-Agent : Pan/0.162 (Pokrosvk)
On Mon, 23 Jun 2025 20:40:21 -0400, Arne Vajhøj wrote:
On 6/23/2025 8:37 PM, Lawrence D'Oliveiro wrote:
>
What a dumb way to do it. Using the null device means making OS I/O
calls -- needless overhead just to find out how long a string -- which
is being put together entirely in userland -- needs to be.
But if you have a simple better way of achieving it ...
snprintf(3) and vsnprintf(3) return the total number of bytes needed for
the final result. So just call them once with all the right arguments and
a zero-length buffer, and use the result to allocate a buffer of the right
length, and call them again.
<
https://manpages.debian.org/vsnprintf(3)>
And of course you should be using va_end(3) and va_start(3) again before
the second call. This allows for traversing the argument list multiple
times.