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: jazepeda@xxxxxxxxxxx
Cc: freeciv-dev@xxxxxxxxxxx
Subject: Re: [Freeciv-Dev] snprintf, again
From: David Pfitzner <dwp@xxxxxxxxxxxxxx>
Date: Wed, 25 Aug 1999 15:48:53 +1000 (EST)

Alex Zepeda wrote:
> On Tue, 24 Aug 1999, David Pfitzner wrote:

> 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.

I'm thinking Win32 and Mac are the main candidates.   
Maybe SunOS too, which seems weird/lacking in many respects, 
although that's a rather low importance target nowadays :-)

Regarding potential Win32 solutions: please be more specific.

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

That sounds like the one libgnome-support (or whatever) uses,
which uses the mprotect trick.  (I would guess OpenBSD would have 
a real vsnprintf as part of its libc and not need to resort to 
such tricks itself.)

> 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; 

I assume you mean g_snprintf in glib (I think).  That uses asprintf 
which does the malloc/copy/free thing, but its still a bit complicated
because you have to parse all the format specifiers, and portability
is non-trivial because you have to worry about type sizes etc,
and also have to do something (configure-wise I think) to work out
how to copy a va_list (which you can't do portably in just standard C)
in order to go through the va_list twice (once to calculate the
upper bound (including strlen for %s etc) and then once for the
vsprintf). 

Its true the the Gtk+ people have presumbaly already solved most 
of these problems, but I am concerned about how ultimately portable, 
bug-free and maintainence-free implementations like this are going 
to be.

Also the glib one contains/uses other glib stuff (like gchar etc) 
which may make it non-trivial to convert to a simple drop-in for 
freeciv.

Speaking of what can be "easily" done, this argument can of 
course be "easily" settled by submitting a patch to add whichever 
snprintf you favour to freeciv, and getting freeciv people to 
test it on their platforms...

Regards,
-- David

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