[Zlib-devel] Re: snprintf

Cosmin Truta cosmin at cs.toronto.edu
Thu Mar 13 15:46:00 EST 2003


"Nelson H. F. Beebe" <beebe at math.utah.edu> wrote:

> I resurveyed about 15 flavors of Unix a couple of days ago in
> connection with installation of another package that needed
> snprintf().  The only one that lacks it is Compaq/DEC Alpha OSF/1 4.0,
> so I'll be able to check whether zlib is handling this properly.
> OSF/1 5.1 DOES have the function.

I also proposed the following lines in zconf.h

#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
#  ifndef STDC
#    define STDC
#  endif
#  ifndef STDC99
#    define STDC99
#  endif
#endif

but right now I think that the following are even better:

#ifdef __STDC_VERSION__
#  ifndef STDC
#    define STDC
#  endif
#  if __STDC_VERSION__ >= 199901L
#    ifndef STDC99
#      define STDC99
#    endif
#  endif
#endif

Technically, __STDC_VERSION__ should be accompanied by __STDC__; but the
second piece of code is more failproof.

When I wrote the zutil.h lines below, I intended them for DOS/WIN and
for other systems that don't run ./configure.
If ./configure can do the job of detecting vsnprintf (e.g. under Unix),
that's fine. Otherwise, any known environment that doesn't support
vsnprintf can be added here.

/* vsnprintf setup */
#if !defined(STDC99) && !(defined(__TURBOC__) && __TURBOC__ >= 0x550)
#  ifdef MSDOS
     /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
        but for now we just assume it doesn't. */
#    define NO_vsnprintf
#  endif
#  ifdef WIN32
     /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
#    if !defined(vsnprintf) && !defined(__TURBOC__)
#      define vsnprintf _vsnprintf
#    endif
#  endif
#  ifdef __TURBOC__
#    define NO_vsnprintf
#  endif
#endif


> One possible solution is to provide a private fallback version of
> snprintf.  I did a Web search, found many, and selected this one:
>
>         http://www.ijs.si/software/snprintf/

Ok. How about this?

/* in zutil.h */
#if defined(NO_vsnprintf) && !defined(USE_vsprintf)
#  define USE_OWN_vsnprintf
#endif

and compile the own vsnprintf under the incidence of USE_OWN_vsnprintf.


Cosmin





More information about the Zlib-devel mailing list