Complete.Org: Mailing Lists: Archives: freeciv-dev: May 1999:
Re: [Freeciv-Dev] patch: provide snprintf
Home

Re: [Freeciv-Dev] patch: provide snprintf

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: Re: [Freeciv-Dev] patch: provide snprintf
From: David Pfitzner <dwp@xxxxxxxxxxxxxx>
Date: Mon, 31 May 1999 13:38:54 +1000 (EST)

Greg Wooledge wrote:

> If I'm reading this right, it allocates a region of memory and uses
> mprotect(2) to cause the program to get a SIGSEGV if it writes outside
> this version.  Then it writes chars to this region using the standard
> vsprintf(3).
> 
> Does this work on all Unix systems?  I would imagine that there may be
> a few without sigaction(2) or mprotect(2) (or both).

Yeah, I agree it looks pretty scary.  Other alternatives used by
other projects/libs to provide snprintf seem to be:

- Mostly full re-implementation of printf (at least format/argument
  parsing).  (Eg JitterBug does this.)  Ouch.

- Implement enough to calculate an upper bound on the output length,
  dynamically allocate that, vsprintf to it, then strncpy, then free
  the temporary memory.  (Eg glib does this for g_snprintf if there
  is no native snprintf.)

Maybe one of these would suit us better.

> I don't have a clue what this would do under Win32, OS/2, AmigaOS, etc.

The current Win32 version uses Cygwin, which I would guess 
already provides a vsnprintf (?), in which case the ugly 
Unix-specific stuff would not be used at all.  No idea about 
others.

-- David

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