Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2000:
[Freeciv-Dev] Re: C99 vsnprintf().
Home

[Freeciv-Dev] Re: C99 vsnprintf().

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: C99 vsnprintf().
From: David Pfitzner <dwp@xxxxxxxxxxxxxx>
Date: Sat, 2 Sep 2000 14:22:30 +1100 (EST)

gs234@xxxxxxxxx (Gaute (B) Strokkenes) wrote:

> Currently, if the native vsnprintf() does not follow the letter of the
> C99 specification, we use a large (64k) buffer and vsprintf() instead.

To be precise, if native vsnprintf() works except for the return value,
we use vsnprintf() into the 64k buffer - vsnprintf for added safety, 
but via buffer to calculate the correct return value.

> Requiring strict adherence to C99 is a in my opinion a bit harsh,
> since there are a lot of systems around with perfectly good
> vsnprintf()'s except for the fact that they do not return the number
> of byte written. 

To be precise again, the correct return value is not the number
of bytes written, but the number of bytes which would have been
written if the user-specified n was large enough to avoid
trunctation.  The essence of the problem is that if the native 
vsnprintf doesn't tell you this, there is no way to work it out 
once truncation has occured (well, except using a larger buffer, 
as in method described above).  Using strlen() after the fact 
doesn't tell you the same information.

OTOH I agree that its an open question whether we really need
this functionality of the return value.

> I think this would be worthwhile, in particular on the Amiga where 64k
> is not that insignificant amount.

My thinking is that 64k is small compared to the rest of freeciv.
That is, if you have enough memory to usefully run freeciv, then 
64k is not much more.

-- David



[Prev in Thread] Current Thread [Next in Thread]