On November 3, 2003 06:09 am, Ferenc Wagner wrote:
In libc-2.1 and later, yes it should. According to MSDN (and pre-2.1 libc docs), it should not.
OK, so we need to care about n not being the size of the required buffer.
Seems like this is the case under Windows. Not under any reasonable modern GNU/Linuxes. However, writing portable code is easy: if the returned value exceeds the buffer length, allocate that much memory and repeat once. No need to loop in this case.
No harm in looping either -- if the correct value is returned, we will just exit right away. If we know for sure that size_t is unsigned (is it always?), than the min() will work just fine. Otherwise, we can rewrite that line as:
size = n < 0 ? size*2 : n+1;
We should probably should anyway, as it makes it a lot more clearer WTF is going on.
By the way, I really managed to screw myself (and my gcc) up by mixing libc calls into winetests.
"Doctor, it hurts when I do that..." :))) I'd say, don't do it. Just use libc calls, don't link against msvcrt. Any reason we need to link against msvcrt at all?