Complete.Org: Mailing Lists: Archives: freeciv-dev: August 1999:
Re: [Freeciv-Dev] snprintf, again
Home

Re: [Freeciv-Dev] snprintf, again

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: David Pfitzner <dwp@xxxxxxxxxxxxxx>
Cc: freeciv-dev@xxxxxxxxxxx
Subject: Re: [Freeciv-Dev] snprintf, again
From: Alex Zepeda <jazepeda@xxxxxxxxxxx>
Date: Tue, 24 Aug 1999 11:59:08 -0700 (PDT)

On Tue, 24 Aug 1999, David Pfitzner wrote:

> Certainly (assuming you really mean vsnprintf).

Yes. :^)

> > which if not available would be IIRC implemented on top of vprintf which
> > nearly everything has AFAIK.
> 
> Huh?  If only it were so easy -- the whole problem is that one
> can't safely implement vsnprintf on top of vsprintf, without 
> doing some trickery like mprotect(), or calculating an upper 
> bound and malloc/strncpy/free, or similar.

Well find a platform that does not have mprotect and does not have
vsnprintf, and currently runs Freeciv (I'm sure there's one, but I just
can't think of one off the top of my head).  This for sure is not Solaris
(which has got to be one of the most aggravating platforms to deal with).
And I'm pretty sure that if Win32 is the problem, there are solutions.

> And be prepared to argue that it doesn't suffer (or doesn't 
> suffer too much) from previously mentioned problems :-)  

Sure.

> And note the licensing must be suitable: apache I think is 
> maybe not (advertising and other clauses); ssh is not open 
> source; Qt remains problematic wrt GPL despite QPL.

Gosh I think Samba has one too, and I know KDE pulled one from Theo de
Raadt (which probably means it's in OpenBSD).

> My previous post was made _after_ previously looking at a few such
> implementations (though certainly not exhastively), and finding 
> a variety of methods (indeed unfortunately _not_ finding one 
> drop-in implementation which everyone clearly agrees is best), 
> with all of them having perceived problems with complexity and/or 
> portability.

Ah hah!  A quick check revealed that the Gtk+ camp has actually done
something decent.  A reasonably portable snprintf.  It appears to use
asprintf (or their own version of it if necesary; this could probably be
tweaked to use *BSDs' asprintf too) and then strncpy the string to the
fixed sized buffer.

Then of course you could forgo snprintf and use asprintf (and simply use
the implementation out of Glib.

And I was just about to argue that mprotect is a rather portable option.

- alex


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