From: Ben Hutchings (ben.hutchings_at_[hidden])
Date: 2004-10-28 05:37:20
Maxim Yegorushkin wrote:
> Ben Hutchings <ben.hutchings_at_[hidden]> wrote:
>>> This is one of the reasons I find the *snprintf functions to be pure
>>> evil. They don't return -1 when the output would be too long, they
>>> return the size they WOULD have written if the buffer was large
>> That's not evil; it's extremely useful if you want to dynamically
>> allocate a large enough buffer. All you have to do is check that the
>> return value is less than or equal to the length you passed in.
> Man pages on my RH 9 AS say that a return value that is *equal* or
> greater than the size of the buffer means that the buffer is too small.
Right, and that agrees with POSIX. I somehow misread the specification
first time around.
> Shouldn't it be
> size_t(n) >= sizeof(buf)
Yes, it should.