6e82b19
diff -up sane-frontends-1.0.14/lib/snprintf.c.OLD sane-frontends-1.0.14/lib/snprintf.c
6e82b19
--- sane-frontends-1.0.14/lib/snprintf.c.OLD	2001-08-03 17:32:56.000000000 -0400
6e82b19
+++ sane-frontends-1.0.14/lib/snprintf.c	2014-05-29 11:09:37.759003520 -0400
6e82b19
@@ -2,180 +2,616 @@
6e82b19
 
6e82b19
 #ifndef HAVE_SNPRINTF
6e82b19
 
6e82b19
-/***************************************************************************
6e82b19
- * LPRng - An Extended Print Spooler System
6e82b19
- *
6e82b19
- * Copyright 1988-1997, Patrick Powell, San Diego, CA
6e82b19
- *     papowell@sdsu.edu
6e82b19
- * See below for conditions of use.
6e82b19
- *
6e82b19
- ***************************************************************************
6e82b19
- * MODULE: snprintf.c
6e82b19
- * PURPOSE: LPRng version of printf - absolutely bombproof (hopefully!)
6e82b19
+/**************************************************************************
6e82b19
+ * Copyright 1994-2003 Patrick Powell, San Diego, CA <papowell@lprng.com>
6e82b19
  **************************************************************************/
6e82b19
-#if 0
6e82b19
-
6e82b19
-			 The "Artistic License"
6e82b19
-
6e82b19
-				Preamble
6e82b19
-
6e82b19
-The intent of this document is to state the conditions under which a
6e82b19
-Package may be copied, such that the Copyright Holder maintains some
6e82b19
-semblance of artistic control over the development of the package,
6e82b19
-while giving the users of the package the right to use and distribute
6e82b19
-the Package in a more-or-less customary fashion, plus the right to make
6e82b19
-reasonable modifications.
6e82b19
-
6e82b19
-Definitions:
6e82b19
-
6e82b19
-	"Package" refers to the collection of files distributed by the
6e82b19
-	Copyright Holder, and derivatives of that collection of files
6e82b19
-	created through textual modification.
6e82b19
-
6e82b19
-	"Standard Version" refers to such a Package if it has not been
6e82b19
-	modified, or has been modified in accordance with the wishes
6e82b19
-	of the Copyright Holder as specified below.
6e82b19
-
6e82b19
-	"Copyright Holder" is whoever is named in the copyright or
6e82b19
-	copyrights for the package.
6e82b19
-
6e82b19
-	"You" is you, if you are thinking about copying or distributing
6e82b19
-	this Package.
6e82b19
-
6e82b19
-	"Reasonable copying fee" is whatever you can justify on the
6e82b19
-	basis of media cost, duplication charges, time of people involved,
6e82b19
-	and so on.  (You will not be required to justify it to the
6e82b19
-	Copyright Holder, but only to the computing community at large
6e82b19
-	as a market that must bear the fee.)
6e82b19
 
6e82b19
-	"Freely Available" means that no fee is charged for the item
6e82b19
-	itself, though there may be fees involved in handling the item.
6e82b19
-	It also means that recipients of the item may redistribute it
6e82b19
-	under the same conditions they received it.
6e82b19
-
6e82b19
-1. You may make and give away verbatim copies of the source form of the
6e82b19
-Standard Version of this Package without restriction, provided that you
6e82b19
-duplicate all of the original copyright notices and associated disclaimers.
6e82b19
-
6e82b19
-2. You may apply bug fixes, portability fixes and other modifications
6e82b19
-derived from the Public Domain or from the Copyright Holder.  A Package
6e82b19
-modified in such a way shall still be considered the Standard Version.
6e82b19
-
6e82b19
-3. You may otherwise modify your copy of this Package in any way, provided
6e82b19
-that you insert a prominent notice in each changed file stating how and
6e82b19
-when you changed that file, and provided that you do at least ONE of the
6e82b19
-following:
6e82b19
-
6e82b19
-    a) place your modifications in the Public Domain or otherwise make them
6e82b19
-    Freely Available, such as by posting said modifications to Usenet or
6e82b19
-    an equivalent medium, or placing the modifications on a major archive
6e82b19
-    site such as uunet.uu.net, or by allowing the Copyright Holder to include
6e82b19
-    your modifications in the Standard Version of the Package.
6e82b19
-
6e82b19
-    b) use the modified Package only within your corporation or organization.
6e82b19
-
6e82b19
-    c) rename any non-standard executables so the names do not conflict
6e82b19
-    with standard executables, which must also be provided, and provide
6e82b19
-    a separate manual page for each non-standard executable that clearly
6e82b19
-    documents how it differs from the Standard Version.
6e82b19
-
6e82b19
-    d) make other distribution arrangements with the Copyright Holder.
6e82b19
-
6e82b19
-4. You may distribute the programs of this Package in object code or
6e82b19
-executable form, provided that you do at least ONE of the following:
6e82b19
+/*
6e82b19
+   Overview:
6e82b19
 
6e82b19
-    a) distribute a Standard Version of the executables and library files,
6e82b19
-    together with instructions (in the manual page or equivalent) on where
6e82b19
-    to get the Standard Version.
6e82b19
+   snprintf( char *buffer, int len, const char *format,...)
6e82b19
+   plp_unsafe_snprintf( char *buffer, int len, const char *format,...)
6e82b19
+     its horribly unsafe companion that does NOT protect you from
6e82b19
+     the printing of evil control characters,  but may be necessary
6e82b19
+     See the man page documentation below
6e82b19
+   
6e82b19
+   This version of snprintf was developed originally for printing
6e82b19
+   on a motley collection of specialized hardware that had NO IO
6e82b19
+   library.  Due to contractual restrictions,  a clean room implementation
6e82b19
+   of the printf() code had to be developed.
6e82b19
+   
6e82b19
+   The method chosen for printf was to be as paranoid as possible,
6e82b19
+   as these platforms had NO memory protection,  and very small
6e82b19
+   address spaces.  This made it possible to try to print
6e82b19
+   very long strings, i.e. - all of memory, very easily.  To guard
6e82b19
+   against this,  all printing was done via a buffer, generous enough
6e82b19
+   to hold strings,  but small enough to protect against overruns,
6e82b19
+   etc.
6e82b19
+   
6e82b19
+   Strangely enough,  this proved to be of immense importance when
6e82b19
+   SPRINTFing to a buffer on a stack...  The rest,  of course,  is
6e82b19
+   well known,  as buffer overruns in the stack are a common way to
6e82b19
+   do horrible things to operating systems, security, etc etc.
6e82b19
+   
6e82b19
+   This version of snprintf is VERY limited by modern standards.
6e82b19
+
6e82b19
+   Revision History:
6e82b19
+   First Released Version - 1994.  This version had NO comments.
6e82b19
+   First Released Version - 1994.  This version had NO comments.
6e82b19
+   Second Major Released Version - Tue May 23 10:43:44 PDT 2000
6e82b19
+    Configuration and other items changed.  Read this doc.
6e82b19
+    Treat this as a new version.
6e82b19
+   Minor Revision - Mon Apr  1 09:41:28 PST 2002
6e82b19
+     - fixed up some constants and casts 
6e82b19
+   
6e82b19
+   COPYRIGHT AND TERMS OF USE:
6e82b19
+   
6e82b19
+   You may use, copy, distribute, or otherwise incorporate this software
6e82b19
+   and documentation into any product or other item,  provided that
6e82b19
+   the copyright in the documentation and source code as well as the
6e82b19
+   source code generated constant strings in the object, executable
6e82b19
+   or other code remain in place and are present in executable modules
6e82b19
+   or objects.
6e82b19
+   
6e82b19
+   You may modify this code as appropriate to your usage; however the
6e82b19
+   modified version must be identified by changing the various source
6e82b19
+   and object code identification strings as is appropriately noted
6e82b19
+   in the source code.
6e82b19
+   
6e82b19
+   You can use this with the GNU CONFIGURE utility.
6e82b19
+   This should define the following macros appropriately:
6e82b19
+   
6e82b19
+   HAVE_STDARG_H - if the <stdargs.h> include file is available
6e82b19
+   HAVE_VARARG_H - if the <varargs.h> include file is available
6e82b19
+   
6e82b19
+   HAVE_STRERROR - if the strerror() routine is available.
6e82b19
+     If it is not available, then examine the lines containing
6e82b19
+     the tests below.
6e82b19
+
6e82b19
+   HAVE_SYS_ERRLIST  - have sys_errlist available
6e82b19
+   HAVE_DECL_SYS_ERRLIST - sys_errlist declaration in include files
6e82b19
+   HAVE_SYS_NERR - have sys_nerr available
6e82b19
+   HAVE_DECL_SYS_NERR -  sys_nerr declaration in include files
6e82b19
+   
6e82b19
+   HAVE_QUAD_T      - if the quad_t type is defined
6e82b19
+   HAVE_LONG_LONG   - if the long long type is defined
6e82b19
+   HAVE_LONG_DOUBLE - if the long double type is defined
6e82b19
+   
6e82b19
+     If you are using the GNU configure (autoconf) facility, add the
6e82b19
+     following line to the configure.in file, to force checking for the
6e82b19
+     quad_t and long long  data types:
6e82b19
+
6e82b19
+
6e82b19
+    AC_CHECK_HEADERS(stdlib.h,stdio.h,unistd.h,errno.h)
6e82b19
+	AC_CHECK_FUNCS(strerror)
6e82b19
+	AC_CACHE_CHECK(for errno,
6e82b19
+	ac_cv_errno,
6e82b19
+	[
6e82b19
+	AC_TRY_LINK(,[extern int errno; return (errno);],
6e82b19
+		ac_cv_errno=yes, ac_cv_errno=no)
6e82b19
+	])
6e82b19
+	if test "$ac_cv_errno" = yes; then
6e82b19
+		AC_DEFINE(HAVE_ERRNO)
6e82b19
+		AC_CACHE_CHECK(for errno declaration,
6e82b19
+		ac_cv_decl_errno,
6e82b19
+		[
6e82b19
+		AC_TRY_COMPILE([
6e82b19
+		#include <stdio.h>
6e82b19
+		#ifdef HAVE_STDLIB_H
6e82b19
+		#include <stdlib.h>
6e82b19
+		#endif
6e82b19
+		#ifdef HAVE_UNISTD_H
6e82b19
+		#include <unistd.h>
6e82b19
+		#endif
6e82b19
+		#ifdef HAVE_ERRNO_H
6e82b19
+		#include <errno.h>
6e82b19
+		],[return(sys_nerr);],
6e82b19
+			ac_cv_decl_errno=yes, ac_cv_decl_errno=no)
6e82b19
+		])
6e82b19
+		if test "$ac_cv_decl_errno" = yes; then
6e82b19
+			AC_DEFINE(HAVE_DECL_ERRNO)
6e82b19
+		fi;
6e82b19
+	fi
6e82b19
+
6e82b19
+	AC_CACHE_CHECK(for sys_nerr,
6e82b19
+	ac_cv_sys_nerr,
6e82b19
+	[
6e82b19
+	AC_TRY_LINK(,[extern int sys_nerr; return (sys_nerr);],
6e82b19
+		ac_cv_sys_nerr=yes, ac_cv_sys_nerr=no)
6e82b19
+	])
6e82b19
+	if test "$ac_cv_sys_nerr" = yes; then
6e82b19
+		AC_DEFINE(HAVE_SYS_NERR)
6e82b19
+		AC_CACHE_CHECK(for sys_nerr declaration,
6e82b19
+		ac_cv_decl_sys_nerr,
6e82b19
+		[
6e82b19
+		AC_TRY_COMPILE([
6e82b19
+		#include <stdio.h>
6e82b19
+		#ifdef HAVE_STDLIB_H
6e82b19
+		#include <stdlib.h>
6e82b19
+		#endif
6e82b19
+		#ifdef HAVE_UNISTD_H
6e82b19
+		#include <unistd.h>
6e82b19
+		#endif],[return(sys_nerr);],
6e82b19
+		ac_cv_decl_sys_nerr_def=yes, ac_cv_decl_sys_nerr_def=no)
6e82b19
+		])
6e82b19
+		if test "$ac_cv_decl_sys_nerr" = yes; then
6e82b19
+			AC_DEFINE(HAVE_DECL_SYS_NERR)
6e82b19
+		fi
6e82b19
+	fi
6e82b19
+
6e82b19
+
6e82b19
+	AC_CACHE_CHECK(for sys_errlist array,
6e82b19
+	ac_cv_sys_errlist,
6e82b19
+	[AC_TRY_LINK(,[extern char *sys_errlist[];
6e82b19
+		sys_errlist[0];],
6e82b19
+		ac_cv_sys_errlist=yes, ac_cv_sys_errlist=no)
6e82b19
+	])
6e82b19
+	if test "$ac_cv_sys_errlist" = yes; then
6e82b19
+		AC_DEFINE(HAVE_SYS_ERRLIST)
6e82b19
+		AC_CACHE_CHECK(for sys_errlist declaration,
6e82b19
+		ac_cv_sys_errlist_def,
6e82b19
+		[AC_TRY_COMPILE([
6e82b19
+		#include <stdio.h>
6e82b19
+		#include <errno.h>
6e82b19
+		#ifdef HAVE_STDLIB_H
6e82b19
+		#include <stdlib.h>
6e82b19
+		#endif
6e82b19
+		#ifdef HAVE_UNISTD_H
6e82b19
+		#include <unistd.h>
6e82b19
+		#endif],[char *s = sys_errlist[0]; return(*s);],
6e82b19
+		ac_cv_decl_sys_errlist=yes, ac_cv_decl_sys_errlist=no)
6e82b19
+		])
6e82b19
+		if test "$ac_cv_decl_sys_errlist" = yes; then
6e82b19
+			AC_DEFINE(HAVE_DECL_SYS_ERRLIST)
6e82b19
+		fi
6e82b19
+	fi
6e82b19
+
6e82b19
+
6e82b19
+
6e82b19
+	AC_CACHE_CHECK(checking for long long,
6e82b19
+	ac_cv_long_long,
6e82b19
+	[
6e82b19
+	AC_TRY_COMPILE([
6e82b19
+	#include <stdio.h>
6e82b19
+	#include <sys/types.h>
6e82b19
+	], [printf("%d",sizeof(long long));],
6e82b19
+	ac_cv_long_long=yes, ac_cv_long_long=no)
6e82b19
+	])
6e82b19
+	if test $ac_cv_long_long = yes; then
6e82b19
+	  AC_DEFINE(HAVE_LONG_LONG)
6e82b19
+	fi
6e82b19
+
6e82b19
+	AC_CACHE_CHECK(checking for long double,
6e82b19
+	ac_cv_long_double,
6e82b19
+	[
6e82b19
+	AC_TRY_COMPILE([
6e82b19
+	#include <stdio.h>
6e82b19
+	#include <sys/types.h>
6e82b19
+	], [printf("%d",sizeof(long double));],
6e82b19
+	ac_cv_long_double=yes, ac_cv_long_double=no)
6e82b19
+	])
6e82b19
+	if test $ac_cv_long_double = yes; then
6e82b19
+	  AC_DEFINE(HAVE_LONG_DOUBLE)
6e82b19
+	fi
6e82b19
+
6e82b19
+	AC_CACHE_CHECK(checking for quad_t,
6e82b19
+	ac_cv_quad_t,
6e82b19
+	[
6e82b19
+	AC_TRY_COMPILE([
6e82b19
+	#include <stdio.h>
6e82b19
+	#include <sys/types.h>
6e82b19
+	], [printf("%d",sizeof(quad_t));],
6e82b19
+	ac_cv_quad_t=yes, ac_cv_quad_t=no)
6e82b19
+	])
6e82b19
+	if test $ac_cv_quad_t = yes; then
6e82b19
+	  AC_DEFINE(HAVE_QUAD_T)
6e82b19
+	fi
6e82b19
+
6e82b19
+
6e82b19
+
6e82b19
+ NAME
6e82b19
+     snprintf, plp_vsnprintf - formatted output conversion
6e82b19
+
6e82b19
+ SYNOPSIS
6e82b19
+     #include <stdio.h>
6e82b19
+     #include <stdarg.h>
6e82b19
+
6e82b19
+     int
6e82b19
+     snprintf(const char *format, size_t size, va_list ap);
6e82b19
+     int
6e82b19
+     plp_unsafe_snprintf(const char *format, size_t size, va_list ap);
6e82b19
+
6e82b19
+     AKA snprintf and unsafe_snprintf in the documentation below
6e82b19
+
6e82b19
+     int
6e82b19
+     vsnprintf(char *str, size_t size, const char *format, va_list ap);
6e82b19
+     int
6e82b19
+     unsafe_vsnprintf(char *str, size_t size, const char *format, va_list ap);
6e82b19
+
6e82b19
+     AKA vsnprintf and unsafe_vsnprintf in the documentation below
6e82b19
+
6e82b19
+     (Multithreaded Safe)
6e82b19
+
6e82b19
+ DESCRIPTION
6e82b19
+     The printf() family of functions produces output according to
6e82b19
+     a format as described below.  Snprintf(), and vsnprintf()
6e82b19
+     write to the character string str. These functions write the
6e82b19
+     output under the control of a format string that specifies
6e82b19
+     how subsequent arguments (or arguments accessed via the
6e82b19
+     variable-length argument facilities of stdarg(3))  are converted
6e82b19
+     for output.  These functions return the number of characters
6e82b19
+     printed (not including the trailing `\0' used to end output
6e82b19
+     to strings).  Snprintf() and vsnprintf() will write at most
6e82b19
+     size-1 of the characters printed into the output string (the
6e82b19
+     size'th character then gets the terminating `\0'); if the
6e82b19
+     return value is greater than or equal to the size argument,
6e82b19
+     the string was too short and some of the printed characters
6e82b19
+     were discarded.  The size or str may be given as zero to find
6e82b19
+     out how many characters are needed; in this case, the str
6e82b19
+     argument is ignored.
6e82b19
+
6e82b19
+     By default, the snprintf function will not format control
6e82b19
+     characters (except new line and tab) in strings.  This is a
6e82b19
+     safety feature that has proven to be extremely critical when
6e82b19
+     using snprintf for secure applications and when debugging.
6e82b19
+     If you MUST have control characters formatted or printed,
6e82b19
+     then use the unsafe_snprintf() and unsafe_vsnprintf() and on
6e82b19
+     your own head be the consequences.  You have been warned.
6e82b19
+
6e82b19
+     There is one exception to the comments above, and that is
6e82b19
+     the "%c" (character) format.  It brutally assumes that the
6e82b19
+     user will have performed the necessary 'isprint()' or other
6e82b19
+     checks and uses the integer value as a character.
6e82b19
+
6e82b19
+     The format string is composed of zero or more directives:
6e82b19
+     ordinary characters (not %), which are copied unchanged to
6e82b19
+     the output stream; and conversion specifications, each
6e82b19
+     of which results in fetching zero or more subsequent arguments.
6e82b19
+     Each conversion specification is introduced by the character
6e82b19
+     %. The arguments must correspond properly (after type promotion)
6e82b19
+     with the conversion specifier.  After the %, the following
6e82b19
+     appear in sequence:
6e82b19
+
6e82b19
+     o   Zero or more of the following flags:
6e82b19
+
6e82b19
+	   -   A zero `0' character specifying zero padding.  For
6e82b19
+	     all conversions except n, the converted value is padded
6e82b19
+	     on the left with zeros rather than blanks.  If a
6e82b19
+	     precision is given with a numeric conversion (d, i,
6e82b19
+	     o, u, i, x, and X), the `0' flag is ignored.
6e82b19
+
6e82b19
+       -   A negative field width flag `-' indicates the converted
6e82b19
+	     value is to be left adjusted on the field boundary.  Except
6e82b19
+	     for n conversions, the converted value is padded on
6e82b19
+	     the right with blanks, rather than on the left with
6e82b19
+	     blanks or zeros.  A `-' overrides a `0' if both are
6e82b19
+	     given.
6e82b19
+
6e82b19
+	   -   A space, specifying that a blank should be left before
6e82b19
+	     a positive number produced by a signed conversion (d, e, E, f,
6e82b19
+	     g, G, or i).
6e82b19
+
6e82b19
+	   -   A `+' character specifying that a sign always be placed
6e82b19
+	     before a number produced by a signed conversion.  A `+' overrides
6e82b19
+	     a space if both are used.
6e82b19
+
6e82b19
+     o   An optional decimal digit string specifying a minimum
6e82b19
+		 field width.  If the converted value has fewer
6e82b19
+		 characters than the field width, it will be padded
6e82b19
+		 with spaces on the left (or right, if the
6e82b19
+		 left-adjustment flag has been given) to fill out
6e82b19
+		 the field width.
6e82b19
+
6e82b19
+     o   An optional precision, in the form of a period `.' followed
6e82b19
+		 by an optional digit string.  If the digit string
6e82b19
+		 is omitted, the precision is taken as zero.  This
6e82b19
+		 gives the minimum number of digits to appear for
6e82b19
+		 d, i, o, u, x, and X conversions, the number of
6e82b19
+		 digits to appear after the decimal-point for e,
6e82b19
+		 E, and f conversions, the maximum number of
6e82b19
+		 significant digits for g and G conversions, or
6e82b19
+		 the maximum number of characters to be printed
6e82b19
+		 from a string for s conversions.
6e82b19
+
6e82b19
+     o   The optional character h, specifying that a following d,
6e82b19
+		 i, o, u, x, or X conversion corresponds to a short
6e82b19
+		 int or unsigned short int argument, or that a
6e82b19
+		 following n conversion corresponds to a pointer
6e82b19
+		 to a short int argument.
6e82b19
+
6e82b19
+     o   The optional character l (ell) specifying that a following
6e82b19
+		 d, i, o, u, x, or X conversion applies to a pointer
6e82b19
+		 to a long int or unsigned long int argument, or
6e82b19
+		 that a following n conversion corresponds to a
6e82b19
+		 pointer to a long int argument.
6e82b19
+
6e82b19
+     o   The optional character q, specifying that a following d,
6e82b19
+		 i, o, u, x, or X conversion corresponds to a quad_t
6e82b19
+		 or u_quad_t argument, or that a following n
6e82b19
+		 conversion corresponds to a quad_t argument.
6e82b19
+         This value is always printed in HEX notation.  Tough.
6e82b19
+         quad_t's are an OS system implementation, and should
6e82b19
+         not be allowed.
6e82b19
+
6e82b19
+     o   The character L specifying that a following e, E, f, g,
6e82b19
+		 or G conversion corresponds to a long double
6e82b19
+		 argument.
6e82b19
+
6e82b19
+     o   A character that specifies the type of conversion to be applied.
6e82b19
+
6e82b19
+
6e82b19
+     A field width or precision, or both, may be indicated by an asterisk `*'
6e82b19
+     instead of a digit string.  In this case, an int argument supplies the
6e82b19
+     field width or precision.  A negative field width is treated as a left
6e82b19
+     adjustment flag followed by a positive field width; a negative precision
6e82b19
+     is treated as though it were missing.
6e82b19
+
6e82b19
+     The conversion specifiers and their meanings are:
6e82b19
+
6e82b19
+     diouxX  The int (or appropriate variant) argument is converted to signed
6e82b19
+			 decimal (d and i), unsigned octal (o), unsigned decimal
6e82b19
+			 (u), or unsigned hexadecimal (x and X) notation.  The
6e82b19
+			 letters abcdef are used for x conversions; the letters
6e82b19
+			 ABCDEF are used for X conversions.  The precision, if
6e82b19
+			 any, gives the minimum number of digits that must
6e82b19
+			 appear; if the converted value requires fewer digits,
6e82b19
+			 it is padded on the left with zeros.
6e82b19
+
6e82b19
+     eE      The double argument is rounded and converted in the style
6e82b19
+             [-]d.ddde+-dd where there is one digit before the decimal-point
6e82b19
+			 character and the number of digits after it is equal
6e82b19
+			 to the precision; if the precision is missing, it is
6e82b19
+			 taken as 6; if the precision is zero, no decimal-point
6e82b19
+			 character appears.  An E conversion uses the letter
6e82b19
+			 E (rather than e) to introduce the exponent.
6e82b19
+			 The exponent always contains at least two digits; if
6e82b19
+			 the value is zero, the exponent is 00.
6e82b19
+
6e82b19
+     f       The double argument is rounded and converted to decimal notation
6e82b19
+             in the style [-]ddd.ddd, where the number of digits after the
6e82b19
+             decimal-point character is equal to the precision specification.
6e82b19
+             If the precision is missing, it is taken as 6; if the precision
6e82b19
+             is explicitly zero, no decimal-point character appears.  If a
6e82b19
+             decimal point appears, at least one digit appears before it.
6e82b19
+
6e82b19
+     g       The double argument is converted in style f or e (or
6e82b19
+			 E for G conversions).  The precision specifies the
6e82b19
+			 number of significant digits.  If the precision is
6e82b19
+			 missing, 6 digits are given; if the precision is zero,
6e82b19
+			 it is treated as 1.  Style e is used if the exponent
6e82b19
+			 from its conversion is less than -4 or greater than
6e82b19
+			 or equal to the precision.  Trailing zeros are removed
6e82b19
+			 from the fractional part of the result; a decimal
6e82b19
+			 point appears only if it is followed by at least one
6e82b19
+			 digit.
6e82b19
+
6e82b19
+     c       The int argument is converted to an unsigned char,
6e82b19
+             and the resulting character is written.
6e82b19
+
6e82b19
+     s       The ``char *'' argument is expected to be a pointer to an array
6e82b19
+			 of character type (pointer to a string).  Characters
6e82b19
+			 from the array are written up to (but not including)
6e82b19
+			 a terminating NUL character; if a precision is
6e82b19
+			 specified, no more than the number specified are
6e82b19
+			 written.  If a precision is given, no null character
6e82b19
+			 need be present; if the precision is not specified,
6e82b19
+			 or is greater than the size of the array, the array
6e82b19
+			 must contain a terminating NUL character.
6e82b19
+
6e82b19
+     %       A `%' is written. No argument is converted. The complete
6e82b19
+             conversion specification is `%%'.
6e82b19
+
6e82b19
+     In no case does a non-existent or small field width cause truncation of a
6e82b19
+     field; if the result of a conversion is wider than the field width, the
6e82b19
+     field is expanded to contain the conversion result.
6e82b19
+
6e82b19
+ EXAMPLES
6e82b19
+     To print a date and time in the form `Sunday, July 3, 10:02', where
6e82b19
+     weekday and month are pointers to strings:
6e82b19
+
6e82b19
+           #include <stdio.h>
6e82b19
+           fprintf(stdout, "%s, %s %d, %.2d:%.2d\n",
6e82b19
+                   weekday, month, day, hour, min);
6e82b19
+
6e82b19
+     To print pi to five decimal places:
6e82b19
+
6e82b19
+           #include <math.h>
6e82b19
+           #include <stdio.h>
6e82b19
+           fprintf(stdout, "pi = %.5f\n", 4 * atan(1.0));
6e82b19
+
6e82b19
+     To allocate a 128 byte string and print into it:
6e82b19
+
6e82b19
+           #include <stdio.h>
6e82b19
+           #include <stdlib.h>
6e82b19
+           #include <stdarg.h>
6e82b19
+           char *newfmt(const char *fmt, ...)
6e82b19
+           {
6e82b19
+               char *p;
6e82b19
+               va_list ap;
6e82b19
+               if ((p = malloc(128)) == NULL)
6e82b19
+                       return (NULL);
6e82b19
+               va_start(ap, fmt);
6e82b19
+               (void) vsnprintf(p, 128, fmt, ap);
6e82b19
+               va_end(ap);
6e82b19
+               return (p);
6e82b19
+           }
6e82b19
+
6e82b19
+ SEE ALSO
6e82b19
+     printf(1),  scanf(3)
6e82b19
+
6e82b19
+ STANDARDS
6e82b19
+     Turkey C Standardization and wimpy POSIX folks did not define
6e82b19
+     snprintf or vsnprintf().
6e82b19
+
6e82b19
+ BUGS
6e82b19
+     The conversion formats %D, %O, and %U are not standard and are provided
6e82b19
+     only for backward compatibility.  The effect of padding the %p format
6e82b19
+     with zeros (either by the `0' flag or by specifying a precision), and the
6e82b19
+     benign effect (i.e., none) of the `#' flag on %n and %p conversions, as
6e82b19
+     well as other nonsensical combinations such as %Ld, are not standard;
6e82b19
+     such combinations should be avoided.
6e82b19
 
6e82b19
-    b) accompany the distribution with the machine-readable source of
6e82b19
-    the Package with your modifications.
6e82b19
+     The typedef names quad_t and u_quad_t are infelicitous.
6e82b19
 
6e82b19
-    c) give non-standard executables non-standard names, and clearly
6e82b19
-    document the differences in manual pages (or equivalent), together
6e82b19
-    with instructions on where to get the Standard Version.
6e82b19
+*/
6e82b19
 
6e82b19
-    d) make other distribution arrangements with the Copyright Holder.
6e82b19
 
6e82b19
-5. You may charge a reasonable copying fee for any distribution of this
6e82b19
-Package.  You may charge any fee you choose for support of this
6e82b19
-Package.  You may not charge a fee for this Package itself.  However,
6e82b19
-you may distribute this Package in aggregate with other (possibly
6e82b19
-commercial) programs as part of a larger (possibly commercial) software
6e82b19
-distribution provided that you do not advertise this Package as a
6e82b19
-product of your own. 
6e82b19
+#include <sys/types.h>
6e82b19
+#include <ctype.h>
6e82b19
+#include <stdlib.h>
6e82b19
+#include <stdio.h>
6e82b19
+#if defined(HAVE_STRING_H)
6e82b19
+# include <string.h>
6e82b19
+#endif
6e82b19
+#if defined(HAVE_STRINGS_H)
6e82b19
+# include <strings.h>
6e82b19
+#endif
6e82b19
+#if defined(HAVE_ERRNO_H)
6e82b19
+#include <errno.h>
6e82b19
+#endif
6e82b19
 
6e82b19
-6. The name of the Copyright Holder may not be used to endorse or promote
6e82b19
-products derived from this software without specific prior written permission.
6e82b19
+/*
6e82b19
+ * For testing, define these values
6e82b19
+ */
6e82b19
+#if 0
6e82b19
+#define HAVE_STDARG_H 1
6e82b19
+#define TEST 1
6e82b19
+#define HAVE_QUAD_T 1
6e82b19
+#endif
6e82b19
 
6e82b19
-7. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
6e82b19
-IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
6e82b19
-WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
6e82b19
+/**** ENDINCLUDE ****/
6e82b19
 
6e82b19
-				The End
6e82b19
-#include "lp.h"
6e82b19
+/*************************************************
6e82b19
+ * KEEP THIS STRING - MODIFY AT THE END WITH YOUR REVISIONS
6e82b19
+ * i.e. - the LOCAL REVISIONS part is for your use
6e82b19
+ *************************************************/
6e82b19
+ 
6e82b19
+ 
6e82b19
+ static char *const _id = "plp_snprintf V2000.08.18 Copyright Patrick Powell 1988-2000 "
6e82b19
+ "$Id: plp_snprintf.c,v 1.4 2005/04/14 20:05:19 papowell Exp $"
6e82b19
+ " LOCAL REVISIONS: renamed plp_snprintf to snprintf, conditionalized everything on HAVE_SNPRINTF";
6e82b19
+
6e82b19
+/* varargs declarations: */
6e82b19
+
6e82b19
+# undef HAVE_STDARGS    /* let's hope that works everywhere (mj) */
6e82b19
+# undef VA_LOCAL_DECL
6e82b19
+# undef VA_START
6e82b19
+# undef VA_SHIFT
6e82b19
+# undef VA_END
6e82b19
+
6e82b19
+#if defined(HAVE_STDARG_H)
6e82b19
+# include <stdarg.h>
6e82b19
+# define HAVE_STDARGS    /* let's hope that works everywhere (mj) */
6e82b19
+# define VA_LOCAL_DECL   va_list ap;
6e82b19
+# define VA_START(f)     va_start(ap, f)
6e82b19
+# define VA_SHIFT(v,t)	;	/* no-op for ANSI */
6e82b19
+# define VA_END          va_end(ap)
6e82b19
+#else
6e82b19
+# if defined(HAVE_VARARGS_H)
6e82b19
+#  include <varargs.h>
6e82b19
+#  undef HAVE_STDARGS
6e82b19
+#  define VA_LOCAL_DECL   va_list ap;
6e82b19
+#  define VA_START(f)     va_start(ap)		/* f is ignored! */
6e82b19
+#  define VA_SHIFT(v,t)	v = va_arg(ap,t)
6e82b19
+#  define VA_END		va_end(ap)
6e82b19
+# else
6e82b19
+ XX ** NO VARARGS ** XX
6e82b19
+# endif
6e82b19
 #endif
6e82b19
 
6e82b19
-#include <stdarg.h>
6e82b19
-#include <errno.h>
6e82b19
-#include <sys/types.h>
6e82b19
-#define HAVE_STDARGS /* let's hope that works everywhere (mj) */
6e82b19
-#define VA_LOCAL_DECL va_list ap;
6e82b19
-#define VA_START(f) va_start(ap, f)
6e82b19
-#define VA_SHIFT(v,t) ; /* no-op for ANSI */
6e82b19
-#define VA_END va_end(ap)
6e82b19
-
6e82b19
-/**** ENDINCLUDE ****/
6e82b19
+ union value {
6e82b19
+#if defined(HAVE_QUAD_T)
6e82b19
+	quad_t qvalue;
6e82b19
+#endif
6e82b19
+#if defined(HAVE_LONG_LONG)
6e82b19
+	long long value;
6e82b19
+#else
6e82b19
+	long value;
6e82b19
+#endif
6e82b19
+	double dvalue;
6e82b19
+};
6e82b19
 
6e82b19
-static char *const _id = "$Id: snprintf.c,v 1.2 2001/08/03 21:32:56 hmg Exp $";
6e82b19
+#undef CVAL 
6e82b19
+#define CVAL(s) (*((unsigned char *)s))
6e82b19
+#define safestrlen(s) ((s)?strlen(s):0)
6e82b19
 
6e82b19
-/*
6e82b19
- * dopr(): poor man's version of doprintf
6e82b19
- */
6e82b19
 
6e82b19
-static char * plp_Errormsg ( int err );
6e82b19
-static void dopr( char *buffer, const char *format, va_list args );
6e82b19
-static void fmtstr(  char *value, int ljust, int len, int zpad, int precision );
6e82b19
-static void fmtnum(  long value, int base, int dosign,
6e82b19
+ static char * plp_Errormsg ( int err, char *buffer );
6e82b19
+ static void dopr( int visible_control, char **buffer, int *left,
6e82b19
+	const char *format, va_list args );
6e82b19
+ static void fmtstr( int visible_control, char **buffer, int *left,
6e82b19
+	char *value, int ljust, int len, int zpad, int precision );
6e82b19
+ static void fmtnum(  char **buffer, int *left,
6e82b19
+	union value *value, int base, int dosign,
6e82b19
+	int ljust, int len, int zpad, int precision );
6e82b19
+#if defined(HAVE_QUAD_T)
6e82b19
+ static void fmtquad(  char **buffer, int *left,
6e82b19
+	union value *value, int base, int dosign,
6e82b19
 	int ljust, int len, int zpad, int precision );
6e82b19
-static void fmtdouble( int fmt, double value,
6e82b19
+#endif
6e82b19
+ static void fmtdouble( char **bufer, int *left,
6e82b19
+	int fmt, double value,
6e82b19
 	int ljust, int len, int zpad, int precision );
6e82b19
-static void dostr( char * );
6e82b19
-static char *output;
6e82b19
-static void dopr_outch( int c );
6e82b19
-static char *end;
6e82b19
-int visible_control = 1;
6e82b19
-
6e82b19
-/**************************************************************
6e82b19
- * Original:
6e82b19
- * Patrick Powell Tue Apr 11 09:48:21 PDT 1995
6e82b19
- * A bombproof version of doprnt (dopr) included.
6e82b19
- * Sigh.  This sort of thing is always nasty do deal with.  Note that
6e82b19
- * the version here does not include floating point...
6e82b19
- *
6e82b19
- * plp_snprintf() is used instead of sprintf() as it does limit checks
6e82b19
- * for string length.  This covers a nasty loophole.
6e82b19
- *
6e82b19
- * The other functions are there to prevent NULL pointers from
6e82b19
- * causing nast effects.
6e82b19
- **************************************************************/
6e82b19
-
6e82b19
-int vsnprintf(char *str, size_t count, const char *fmt, va_list args)
6e82b19
-{
6e82b19
-	str[0] = 0;
6e82b19
-	end = str+count-1;
6e82b19
-	dopr( str, fmt, args );
6e82b19
-	if( count>0 ){
6e82b19
-		end[0] = 0;
6e82b19
+ static void dostr(  char **buffer, int *left, char *str );
6e82b19
+ static void dopr_outch(  char **buffer, int *left, int c );
6e82b19
+/* VARARGS3 */
6e82b19
+#ifdef HAVE_STDARGS
6e82b19
+ int plp_vsnprintf(char *str, size_t count, const char *fmt, va_list args)
6e82b19
+#else
6e82b19
+ int plp_vsnprintf(char *str, size_t count, const char *fmt, va_list args)
6e82b19
+#endif
6e82b19
+
6e82b19
+{
6e82b19
+	int left;
6e82b19
+	char *buffer;
6e82b19
+	if( (int)count < 0 ) count = 0;
6e82b19
+	left = count;
6e82b19
+	if( count == 0 ) str = 0;
6e82b19
+	buffer = str;
6e82b19
+	dopr( 1, &buffer, &left, fmt, args );
6e82b19
+	/* fprintf(stderr,"str 0x%x, buffer 0x%x, count %d, left %d\n",
6e82b19
+		(int)str, (int)buffer, count, left ); */
6e82b19
+	if( str && count > 0 ){
6e82b19
+		if( left > 0 ){
6e82b19
+			str[count-left] = 0;
6e82b19
+		} else {
6e82b19
+			str[count-1] = 0;
6e82b19
+		}
6e82b19
+	}
6e82b19
+	return(count - left);
6e82b19
+}
6e82b19
+
6e82b19
+/* VARARGS3 */
6e82b19
+#ifdef HAVE_STDARGS
6e82b19
+ int plp_unsafe_vsnprintf(char *str, size_t count, const char *fmt, va_list args)
6e82b19
+#else
6e82b19
+ int plp_unsafe_vsnprintf(char *str, size_t count, const char *fmt, va_list args)
6e82b19
+#endif
6e82b19
+{
6e82b19
+	int left;
6e82b19
+	char *buffer;
6e82b19
+	if( (int)count < 0 ) count = 0;
6e82b19
+	left = count;
6e82b19
+	if( count == 0 ) str = 0;
6e82b19
+	buffer = str;
6e82b19
+	dopr( 0, &buffer, &left, fmt, args );
6e82b19
+	/* fprintf(stderr,"str 0x%x, buffer 0x%x, count %d, left %d\n",
6e82b19
+		(int)str, (int)buffer, count, left ); */
6e82b19
+	if( str && count > 0 ){
6e82b19
+		if( left > 0 ){
6e82b19
+			str[count-left] = 0;
6e82b19
+		} else {
6e82b19
+			str[count-1] = 0;
6e82b19
+		}
6e82b19
 	}
6e82b19
-	return(strlen(str));
6e82b19
+	return(count - left);
6e82b19
 }
6e82b19
 
6e82b19
 /* VARARGS3 */
6e82b19
 #ifdef HAVE_STDARGS
6e82b19
-int snprintf (char *str,size_t count,const char *fmt,...)
6e82b19
+ int snprintf (char *str,size_t count,const char *fmt,...)
6e82b19
 #else
6e82b19
-int snprintf (va_alist) va_dcl
6e82b19
+ int snprintf (va_alist) va_dcl
6e82b19
 #endif
6e82b19
 {
6e82b19
 #ifndef HAVE_STDARGS
6e82b19
@@ -183,22 +619,48 @@ int snprintf (va_alist) va_dcl
6e82b19
 	size_t count;
6e82b19
     char *fmt;
6e82b19
 #endif
6e82b19
+	int n = 0;
6e82b19
     VA_LOCAL_DECL
6e82b19
 
6e82b19
     VA_START (fmt);
6e82b19
     VA_SHIFT (str, char *);
6e82b19
     VA_SHIFT (count, size_t );
6e82b19
     VA_SHIFT (fmt, char *);
6e82b19
-    (void) vsnprintf ( str, count, fmt, ap);
6e82b19
+    n = plp_vsnprintf ( str, count, fmt, ap);
6e82b19
     VA_END;
6e82b19
-	return( strlen( str ) );
6e82b19
+	return( n );
6e82b19
 }
6e82b19
 
6e82b19
-static void dopr( char *buffer, const char *format, va_list args )
6e82b19
+
6e82b19
+/* VARARGS3 */
6e82b19
+#ifdef HAVE_STDARGS
6e82b19
+ int plp_unsafe_snprintf (char *str,size_t count,const char *fmt,...)
6e82b19
+#else
6e82b19
+ int plp_unsafe_snprintf (va_alist) va_dcl
6e82b19
+#endif
6e82b19
+{
6e82b19
+#ifndef HAVE_STDARGS
6e82b19
+    char *str;
6e82b19
+	size_t count;
6e82b19
+    char *fmt;
6e82b19
+#endif
6e82b19
+	int n = 0;
6e82b19
+    VA_LOCAL_DECL
6e82b19
+
6e82b19
+    VA_START (fmt);
6e82b19
+    VA_SHIFT (str, char *);
6e82b19
+    VA_SHIFT (count, size_t );
6e82b19
+    VA_SHIFT (fmt, char *);
6e82b19
+    n = plp_unsafe_vsnprintf ( str, count, fmt, ap);
6e82b19
+    VA_END;
6e82b19
+	return( n );
6e82b19
+}
6e82b19
+ static void dopr( int visible_control, char **buffer, int *left, const char *format, va_list args )
6e82b19
 {
6e82b19
 	int ch;
6e82b19
-	long value;
6e82b19
+	union value value;
6e82b19
 	int longflag = 0;
6e82b19
+	int quadflag = 0;
6e82b19
 	char *strvalue;
6e82b19
 	int ljust;
6e82b19
 	int len;
6e82b19
@@ -207,22 +669,30 @@ static void dopr( char *buffer, const ch
6e82b19
 	int set_precision;
6e82b19
 	double dval;
6e82b19
 	int err = errno;
6e82b19
+	int base = 0;
6e82b19
+	int signed_val = 0;
6e82b19
 
6e82b19
-	output = buffer;
6e82b19
 	while( (ch = *format++) ){
6e82b19
 		switch( ch ){
6e82b19
 		case '%':
6e82b19
-			ljust = len = zpad = 0;
6e82b19
+			longflag = quadflag =
6e82b19
+			ljust = len = zpad = base = signed_val = 0;
6e82b19
 			precision = -1; set_precision = 0;
6e82b19
 		nextch: 
6e82b19
 			ch = *format++;
6e82b19
 			switch( ch ){
6e82b19
 			case 0:
6e82b19
-				dostr( "**end of format**" );
6e82b19
+				dostr( buffer, left, "**end of format**" );
6e82b19
 				return;
6e82b19
 			case '-': ljust = 1; goto nextch;
6e82b19
 			case '.': set_precision = 1; precision = 0; goto nextch;
6e82b19
-			case '*': len = va_arg( args, int ); goto nextch;
6e82b19
+			case '*':
6e82b19
+				if( set_precision ){
6e82b19
+					precision = va_arg( args, int );
6e82b19
+				} else {
6e82b19
+					len = va_arg( args, int );
6e82b19
+				}
6e82b19
+				goto nextch;
6e82b19
 			case '0': /* set zero padding if len not set */
6e82b19
 				if(len==0 && set_precision == 0 ) zpad = '0';
6e82b19
 			case '1': case '2': case '3':
6e82b19
@@ -234,76 +704,91 @@ static void dopr( char *buffer, const ch
6e82b19
 					len = len*10 + ch - '0';
6e82b19
 				}
6e82b19
 				goto nextch;
6e82b19
-			case 'l': longflag = 1; goto nextch;
6e82b19
+			case 'l': ++longflag; goto nextch;
6e82b19
+			case 'q':
6e82b19
+#if !defined( HAVE_QUAD_T )
6e82b19
+					dostr( buffer, left, "*no quad_t support *");
6e82b19
+					return;
6e82b19
+#endif
6e82b19
+					quadflag = 1;
6e82b19
+					goto nextch;
6e82b19
 			case 'u': case 'U':
6e82b19
-				/*fmtnum(value,base,dosign,ljust,len, zpad, precision) */
6e82b19
-				if( longflag ){
6e82b19
-					value = va_arg( args, long );
6e82b19
-				} else {
6e82b19
-					value = va_arg( args, int );
6e82b19
-				}
6e82b19
-				fmtnum( value, 10,0, ljust, len, zpad, precision ); break;
6e82b19
+				if( base == 0 ){ base = 10; signed_val = 0; }
6e82b19
 			case 'o': case 'O':
6e82b19
-				/*fmtnum(value,base,dosign,ljust,len, zpad, precision) */
6e82b19
-				if( longflag ){
6e82b19
-					value = va_arg( args, long );
6e82b19
-				} else {
6e82b19
-					value = va_arg( args, int );
6e82b19
-				}
6e82b19
-				fmtnum( value, 8,0, ljust, len, zpad, precision ); break;
6e82b19
+				if( base == 0 ){ base = 8; signed_val = 0; }
6e82b19
 			case 'd': case 'D':
6e82b19
-				if( longflag ){
6e82b19
-					value = va_arg( args, long );
6e82b19
-				} else {
6e82b19
-					value = va_arg( args, int );
6e82b19
-				}
6e82b19
-				fmtnum( value, 10,1, ljust, len, zpad, precision ); break;
6e82b19
+				if( base == 0 ){ base = 10; signed_val = 1; }
6e82b19
 			case 'x':
6e82b19
-				if( longflag ){
6e82b19
-					value = va_arg( args, long );
6e82b19
-				} else {
6e82b19
-					value = va_arg( args, int );
6e82b19
-				}
6e82b19
-				fmtnum( value, 16,0, ljust, len, zpad, precision ); break;
6e82b19
+				if( base == 0 ){ base = 16; signed_val = 0; }
6e82b19
 			case 'X':
6e82b19
-				if( longflag ){
6e82b19
-					value = va_arg( args, long );
6e82b19
+				if( base == 0 ){ base = -16; signed_val = 0; }
6e82b19
+#if defined( HAVE_QUAD_T )
6e82b19
+				if( quadflag ){
6e82b19
+					value.qvalue = va_arg( args, quad_t );
6e82b19
+					fmtquad( buffer, left,  &value,base,signed_val, ljust, len, zpad, precision );
6e82b19
+					break;
6e82b19
+				} else
6e82b19
+#endif
6e82b19
+				if( longflag > 1 ){
6e82b19
+#if defined(HAVE_LONG_LONG)
6e82b19
+					if( signed_val ){
6e82b19
+					value.value = va_arg( args, long long );
6e82b19
+					} else {
6e82b19
+					value.value = va_arg( args, unsigned long long );
6e82b19
+					}
6e82b19
+#else
6e82b19
+					if( signed_val ){
6e82b19
+					value.value = va_arg( args, long );
6e82b19
+					} else {
6e82b19
+					value.value = va_arg( args, unsigned long );
6e82b19
+					}
6e82b19
+#endif
6e82b19
+				} else if( longflag ){
6e82b19
+					if( signed_val ){
6e82b19
+						value.value = va_arg( args, long );
6e82b19
+					} else {
6e82b19
+						value.value = va_arg( args, unsigned long );
6e82b19
+					}
6e82b19
 				} else {
6e82b19
-					value = va_arg( args, int );
6e82b19
+					if( signed_val ){
6e82b19
+						value.value = va_arg( args, int );
6e82b19
+					} else {
6e82b19
+						value.value = va_arg( args, unsigned int );
6e82b19
+					}
6e82b19
 				}
6e82b19
-				fmtnum( value,-16,0, ljust, len, zpad, precision ); break;
6e82b19
+				fmtnum( buffer, left,  &value,base,signed_val, ljust, len, zpad, precision ); break;
6e82b19
 			case 's':
6e82b19
 				strvalue = va_arg( args, char *);
6e82b19
-				fmtstr( strvalue,ljust,len, zpad, precision );
6e82b19
+				fmtstr( visible_control, buffer, left, strvalue,ljust,len, zpad, precision );
6e82b19
 				break;
6e82b19
 			case 'c':
6e82b19
 				ch = va_arg( args, int );
6e82b19
 				{ char b[2];
6e82b19
-					int vsb = visible_control;
6e82b19
 					b[0] = ch;
6e82b19
 					b[1] = 0;
6e82b19
-					visible_control = 0;
6e82b19
-					fmtstr( b,ljust,len, zpad, precision );
6e82b19
-					visible_control = vsb;
6e82b19
+					fmtstr( 0, buffer, left, b,ljust,len, zpad, precision );
6e82b19
 				}
6e82b19
 				break;
6e82b19
-			case 'f': case 'g':
6e82b19
+			case 'f': case 'g': case 'e':
6e82b19
 				dval = va_arg( args, double );
6e82b19
-				fmtdouble( ch, dval,ljust,len, zpad, precision ); break;
6e82b19
+				fmtdouble( buffer, left, ch, dval,ljust,len, zpad, precision ); break;
6e82b19
 			case 'm':
6e82b19
-				fmtstr( plp_Errormsg(err),ljust,len, zpad, precision ); break;
6e82b19
-			case '%': dopr_outch( ch ); continue;
6e82b19
+				{ char shortbuffer[32];
6e82b19
+				fmtstr( visible_control, buffer, left,
6e82b19
+					plp_Errormsg(err, shortbuffer),ljust,len, zpad, precision );
6e82b19
+				}
6e82b19
+				break;
6e82b19
+			case '%': dopr_outch( buffer, left, ch ); continue;
6e82b19
 			default:
6e82b19
-				dostr(  "???????" );
6e82b19
+				dostr(  buffer, left, "???????" );
6e82b19
 			}
6e82b19
 			longflag = 0;
6e82b19
 			break;
6e82b19
 		default:
6e82b19
-			dopr_outch( ch );
6e82b19
+			dopr_outch( buffer, left, ch );
6e82b19
 			break;
6e82b19
 		}
6e82b19
 	}
6e82b19
-	*output = 0;
6e82b19
 }
6e82b19
 
6e82b19
 /*
6e82b19
@@ -312,63 +797,69 @@ static void dopr( char *buffer, const ch
6e82b19
  * len = minimum length
6e82b19
  * precision = numbers of chars in string to use
6e82b19
  */
6e82b19
-static void
6e82b19
-fmtstr(  char *value, int ljust, int len, int zpad, int precision )
6e82b19
+ static void
6e82b19
+ fmtstr( int visible_control, char **buffer, int *left,
6e82b19
+	 char *value, int ljust, int len, int zpad, int precision )
6e82b19
 {
6e82b19
-	int padlen, strlen, i, c;	/* amount to pad */
6e82b19
+	int padlen, strlenv, i, c;	/* amount to pad */
6e82b19
 
6e82b19
 	if( value == 0 ){
6e82b19
 		value = "<NULL>";
6e82b19
 	}
6e82b19
-	if( precision > 0 ){
6e82b19
-		strlen = precision;
6e82b19
-	} else {
6e82b19
-		/* cheap strlen so you do not have library call */
6e82b19
-		for( strlen = 0; (c=value[strlen]); ++ strlen ){
6e82b19
-			if( visible_control && iscntrl( c ) && !isspace( c ) ){
6e82b19
-				++strlen;
6e82b19
-			}
6e82b19
+	/* cheap strlen so you do not have library call */
6e82b19
+	for( strlenv = i = 0; (c=CVAL(value+i)); ++i ){
6e82b19
+		if( visible_control && iscntrl( c ) && c != '\t' && c != '\n' ){
6e82b19
+			++strlenv;
6e82b19
 		}
6e82b19
+		++strlenv;
6e82b19
 	}
6e82b19
-	padlen = len - strlen;
6e82b19
+	if( precision > 0 && strlenv > precision ){
6e82b19
+		strlenv = precision;
6e82b19
+	}
6e82b19
+	padlen = len - strlenv;
6e82b19
 	if( padlen < 0 ) padlen = 0;
6e82b19
 	if( ljust ) padlen = -padlen;
6e82b19
 	while( padlen > 0 ) {
6e82b19
-		dopr_outch( ' ' );
6e82b19
+		dopr_outch( buffer, left, ' ' );
6e82b19
 		--padlen;
6e82b19
 	}
6e82b19
 	/* output characters */
6e82b19
-	for( i = 0; (c = value[i]); ++i ){
6e82b19
-		if( visible_control && iscntrl( c ) && !isspace( c ) ){
6e82b19
-			dopr_outch('^');
6e82b19
+	for( i = 0; i < strlenv && (c = CVAL(value+i)); ++i ){
6e82b19
+		if( visible_control && iscntrl( c ) && c != '\t' && c != '\n' ){
6e82b19
+			dopr_outch(buffer, left, '^');
6e82b19
 			c = ('@' | (c & 0x1F));
6e82b19
 		}
6e82b19
-		dopr_outch(c);
6e82b19
+		dopr_outch(buffer, left, c);
6e82b19
 	}
6e82b19
 	while( padlen < 0 ) {
6e82b19
-		dopr_outch( ' ' );
6e82b19
+		dopr_outch( buffer, left, ' ' );
6e82b19
 		++padlen;
6e82b19
 	}
6e82b19
 }
6e82b19
 
6e82b19
-static void
6e82b19
-fmtnum(  long value, int base, int dosign, int ljust,
6e82b19
+ static void
6e82b19
+ fmtnum( char **buffer, int *left,
6e82b19
+	union value *value, int base, int dosign, int ljust,
6e82b19
 	int len, int zpad, int precision )
6e82b19
 {
6e82b19
 	int signvalue = 0;
6e82b19
+#if defined(HAVE_LONG_LONG)
6e82b19
+	unsigned long long uvalue;
6e82b19
+#else
6e82b19
 	unsigned long uvalue;
6e82b19
-	char convert[20];
6e82b19
+#endif
6e82b19
+	char convert[sizeof( union value) * 8 + 16];
6e82b19
 	int place = 0;
6e82b19
 	int padlen = 0;	/* amount to pad */
6e82b19
 	int caps = 0;
6e82b19
 
6e82b19
-	/* DEBUGP(("value 0x%x, base %d, dosign %d, ljust %d, len %d, zpad %d\n",
6e82b19
-		value, base, dosign, ljust, len, zpad )); */
6e82b19
-	uvalue = value;
6e82b19
+	/* fprintf(stderr,"value 0x%x, base %d, dosign %d, ljust %d, len %d, zpad %d\n",
6e82b19
+		value, base, dosign, ljust, len, zpad );/ **/
6e82b19
+	uvalue = value->value;
6e82b19
 	if( dosign ){
6e82b19
-		if( value < 0 ) {
6e82b19
+		if( value->value < 0 ) {
6e82b19
 			signvalue = '-';
6e82b19
-			uvalue = -value; 
6e82b19
+			uvalue = -value->value; 
6e82b19
 		}
6e82b19
 	}
6e82b19
 	if( base < 0 ){
6e82b19
@@ -385,71 +876,148 @@ fmtnum(  long value, int base, int dosig
6e82b19
 	padlen = len - place;
6e82b19
 	if( padlen < 0 ) padlen = 0;
6e82b19
 	if( ljust ) padlen = -padlen;
6e82b19
-	/* DEBUGP(( "str '%s', place %d, sign %c, padlen %d\n",
6e82b19
-		convert,place,signvalue,padlen)); */
6e82b19
+	/* fprintf( stderr, "str '%s', place %d, sign %c, padlen %d\n",
6e82b19
+		convert,place,signvalue,padlen); / **/
6e82b19
 	if( zpad && padlen > 0 ){
6e82b19
 		if( signvalue ){
6e82b19
-			dopr_outch( signvalue );
6e82b19
+			dopr_outch( buffer, left, signvalue );
6e82b19
 			--padlen;
6e82b19
 			signvalue = 0;
6e82b19
 		}
6e82b19
 		while( padlen > 0 ){
6e82b19
-			dopr_outch( zpad );
6e82b19
+			dopr_outch( buffer, left, zpad );
6e82b19
 			--padlen;
6e82b19
 		}
6e82b19
 	}
6e82b19
 	while( padlen > 0 ) {
6e82b19
-		dopr_outch( ' ' );
6e82b19
+		dopr_outch( buffer, left, ' ' );
6e82b19
 		--padlen;
6e82b19
 	}
6e82b19
-	if( signvalue ) dopr_outch( signvalue );
6e82b19
-	while( place > 0 ) dopr_outch( convert[--place] );
6e82b19
+	if( signvalue ) dopr_outch( buffer, left, signvalue );
6e82b19
+	while( place > 0 ) dopr_outch( buffer, left, convert[--place] );
6e82b19
 	while( padlen < 0 ){
6e82b19
-		dopr_outch( ' ' );
6e82b19
+		dopr_outch( buffer, left, ' ' );
6e82b19
 		++padlen;
6e82b19
 	}
6e82b19
 }
6e82b19
 
6e82b19
-static void
6e82b19
-fmtdouble( int fmt, double value, int ljust, int len, int zpad, int precision )
6e82b19
+#if defined(HAVE_QUAD_T)
6e82b19
+
6e82b19
+ static void
6e82b19
+ fmtquad( char **buffer, int *left,
6e82b19
+	union value *value, int base, int dosign, int ljust,
6e82b19
+	int len, int zpad, int precision )
6e82b19
 {
6e82b19
-	char convert[128];
6e82b19
-	char fmtstr[128];
6e82b19
-	int l;
6e82b19
+	int signvalue = 0;
6e82b19
+	int place = 0;
6e82b19
+	int padlen = 0;	/* amount to pad */
6e82b19
+	int caps = 0;
6e82b19
+	int i, c;
6e82b19
+	union {
6e82b19
+		quad_t qvalue;
6e82b19
+		unsigned char qconvert[sizeof(quad_t)];
6e82b19
+	} vvalue;
6e82b19
+	char convert[2*sizeof(quad_t)+1];
6e82b19
+
6e82b19
+	/* fprintf(stderr,"value 0x%x, base %d, dosign %d, ljust %d, len %d, zpad %d\n",
6e82b19
+		value, base, dosign, ljust, len, zpad );/ **/
6e82b19
+	vvalue.qvalue = value->qvalue;
6e82b19
 
6e82b19
-	if( len == 0 ) len = 10;
6e82b19
-	if( len > sizeof(convert) - 10 ){
6e82b19
-		len = sizeof(convert) - 10;
6e82b19
+	if( base < 0 ){
6e82b19
+		caps = 1;
6e82b19
 	}
6e82b19
-	if( precision > sizeof(convert) - 10 ){
6e82b19
-		precision = sizeof(convert) - 10;
6e82b19
+
6e82b19
+	for( i = 0; i < (int)sizeof(quad_t); ++i ){
6e82b19
+		c = vvalue.qconvert[i];
6e82b19
+		convert[2*i] = 
6e82b19
+			(caps? "0123456789ABCDEF":"0123456789abcdef")[ (c >> 4) & 0xF];
6e82b19
+		convert[2*i+1] = 
6e82b19
+			(caps? "0123456789ABCDEF":"0123456789abcdef")[ c  & 0xF];
6e82b19
 	}
6e82b19
-	if( precision > len ) precision = len;
6e82b19
-	strcpy( fmtstr, "%" );
6e82b19
-	if( ljust ) strcat(fmtstr, "-" );
6e82b19
-	if( len ){
6e82b19
-		sprintf( fmtstr+strlen(fmtstr), "%d", len );
6e82b19
+	convert[2*i] = 0;
6e82b19
+
6e82b19
+	place = strlen(convert);
6e82b19
+	padlen = len - place;
6e82b19
+	if( padlen < 0 ) padlen = 0;
6e82b19
+	if( ljust ) padlen = -padlen;
6e82b19
+	/* fprintf( stderr, "str '%s', place %d, sign %c, padlen %d\n",
6e82b19
+		convert,place,signvalue,padlen); / **/
6e82b19
+	if( zpad && padlen > 0 ){
6e82b19
+		if( signvalue ){
6e82b19
+			dopr_outch( buffer, left, signvalue );
6e82b19
+			--padlen;
6e82b19
+			signvalue = 0;
6e82b19
+		}
6e82b19
+		while( padlen > 0 ){
6e82b19
+			dopr_outch( buffer, left, zpad );
6e82b19
+			--padlen;
6e82b19
+		}
6e82b19
+	}
6e82b19
+	while( padlen > 0 ) {
6e82b19
+		dopr_outch( buffer, left, ' ' );
6e82b19
+		--padlen;
6e82b19
+	}
6e82b19
+	if( signvalue ) dopr_outch( buffer, left, signvalue );
6e82b19
+	while( place > 0 ) dopr_outch( buffer, left, convert[--place] );
6e82b19
+	while( padlen < 0 ){
6e82b19
+		dopr_outch( buffer, left, ' ' );
6e82b19
+		++padlen;
6e82b19
+	}
6e82b19
+}
6e82b19
+
6e82b19
+#endif
6e82b19
+
6e82b19
+ static void mystrcat(char *dest, char *src )
6e82b19
+{
6e82b19
+	if( dest && src ){
6e82b19
+		dest += safestrlen(dest);
6e82b19
+		strcpy(dest,src);
6e82b19
+	}
6e82b19
+}
6e82b19
+
6e82b19
+ static void
6e82b19
+ fmtdouble( char **buffer, int *left,
6e82b19
+	int fmt, double value, int ljust, int len, int zpad, int precision )
6e82b19
+{
6e82b19
+	char convert[sizeof( union value) * 8 + 512];
6e82b19
+	char formatstr[128];
6e82b19
+
6e82b19
+	/* fprintf(stderr,"len %d, precision %d\n", len, precision ); */
6e82b19
+	if( len > 255 ){
6e82b19
+		len = 255;
6e82b19
+	}
6e82b19
+	if( precision > 255 ){
6e82b19
+		precision = 255;
6e82b19
+	}
6e82b19
+	if( precision >= 0 && len > 0 && precision > len ) precision = len;
6e82b19
+	strcpy( formatstr, "%" );		/* 1 */
6e82b19
+	if( ljust ) mystrcat(formatstr, "-" ); /* 1 */
6e82b19
+	if( zpad ) mystrcat(formatstr, "0" );	/* 1 */
6e82b19
+	if( len >= 0 ){
6e82b19
+		sprintf( formatstr+strlen(formatstr), "%d", len ); /* 3 */
6e82b19
 	}
6e82b19
-	if( precision > 0 ){
6e82b19
-		sprintf( fmtstr+strlen(fmtstr), ".%d", precision );
6e82b19
+	if( precision >= 0 ){
6e82b19
+		sprintf( formatstr+strlen(formatstr), ".%d", precision ); /* 3 */
6e82b19
 	}
6e82b19
-	l = strlen( fmtstr );
6e82b19
-	fmtstr[l] = fmt;
6e82b19
-	fmtstr[l+1] = 0;
6e82b19
-	sprintf( convert, fmtstr, value );
6e82b19
-	dostr( convert );
6e82b19
+	/* format string will be at most 10 chars long ... */
6e82b19
+	sprintf( formatstr+strlen(formatstr), "%c", fmt );
6e82b19
+	/* this is easier than trying to do the portable dtostr */
6e82b19
+	/* fprintf(stderr,"format string '%s'\n", formatstr); */
6e82b19
+	sprintf( convert, formatstr, value );
6e82b19
+	dostr( buffer, left, convert );
6e82b19
 }
6e82b19
 
6e82b19
-static void dostr( char *str )
6e82b19
+ static void dostr( char **buffer, int *left, char *str  )
6e82b19
 {
6e82b19
-	while(*str) dopr_outch(*str++);
6e82b19
+	if(str)while(*str) dopr_outch( buffer, left, *str++ );
6e82b19
 }
6e82b19
 
6e82b19
-static void dopr_outch( int c )
6e82b19
+ static void dopr_outch( char **buffer, int *left, int c )
6e82b19
 {
6e82b19
-	if( end == 0 || output < end ){
6e82b19
-		*output++ = c;
6e82b19
+	if( *left > 0 ){
6e82b19
+		*(*buffer)++ = c;
6e82b19
 	}
6e82b19
+	*left -= 1;
6e82b19
 }
6e82b19
 
6e82b19
 
6e82b19
@@ -461,29 +1029,26 @@ static void dopr_outch( int c )
6e82b19
  *  Patrick Powell Tue Apr 11 08:05:05 PDT 1995
6e82b19
  ****************************************************************************/
6e82b19
 /****************************************************************************/
6e82b19
-#if !defined(HAVE_STRERROR)
6e82b19
-
6e82b19
-# if defined(HAVE_SYS_NERR)
6e82b19
-#  if !defined(HAVE_SYS_NERR_DEF)
6e82b19
-     extern int sys_nerr;
6e82b19
-#  endif
6e82b19
-#  define num_errors    (sys_nerr)
6e82b19
-# else
6e82b19
-#  define num_errors    (-1)            /* always use "errno=%d" */
6e82b19
-# endif
6e82b19
 
6e82b19
+#if !defined(HAVE_STRERROR)
6e82b19
+# undef  num_errors
6e82b19
 # if defined(HAVE_SYS_ERRLIST)
6e82b19
-#  if !defined(HAVE_SYS_ERRLIST_DEF)
6e82b19
+#  if !defined(HAVE_DECL_SYS_ERRLIST)
6e82b19
      extern const char *const sys_errlist[];
6e82b19
 #  endif
6e82b19
-# else
6e82b19
-#  undef  num_errors
6e82b19
-#  define num_errors   (-1)            /* always use "errno=%d" */
6e82b19
+#  if defined(HAVE_SYS_NERR)
6e82b19
+#   if !defined(HAVE_DECL_SYS_NERR)
6e82b19
+      extern int sys_nerr;
6e82b19
+#   endif
6e82b19
+#   define num_errors    (sys_nerr)
6e82b19
+#  endif
6e82b19
+# endif
6e82b19
+# if !defined(num_errors)
6e82b19
+#   define num_errors   (-1)            /* always use "errno=%d" */
6e82b19
 # endif
6e82b19
-
6e82b19
 #endif
6e82b19
 
6e82b19
-static char * plp_Errormsg ( int err )
6e82b19
+ static char * plp_Errormsg ( int err, char *buffer /* int maxlen = 32 */)
6e82b19
 {
6e82b19
     char *cp;
6e82b19
 
6e82b19
@@ -496,10 +1061,8 @@ static char * plp_Errormsg ( int err )
6e82b19
     } else
6e82b19
 # endif
6e82b19
 	{
6e82b19
-		static char msgbuf[32];     /* holds "errno=%d". */
6e82b19
-		/* SAFE use of sprintf */
6e82b19
-		(void) sprintf (msgbuf, "errno=%d", err);
6e82b19
-		cp = msgbuf;
6e82b19
+		(void) sprintf (buffer, "errno=%d", err);
6e82b19
+		cp = buffer;
6e82b19
     }
6e82b19
 #endif
6e82b19
     return (cp);
6e82b19
@@ -507,23 +1070,47 @@ static char * plp_Errormsg ( int err )
6e82b19
 
6e82b19
 #if defined(TEST)
6e82b19
 #include <stdio.h>
6e82b19
-int main( void )
6e82b19
+ int main( void )
6e82b19
 {
6e82b19
 	char buffer[128];
6e82b19
 	char *t;
6e82b19
 	char *test1 = "01234";
6e82b19
+	int n;
6e82b19
 	errno = 1;
6e82b19
-	plp_snprintf( buffer, sizeof(buffer), (t="errno '%m'")); printf( "%s = '%s'\n", t, buffer );
6e82b19
-	plp_snprintf( buffer, sizeof(buffer), (t = "%s"), test1 ); printf( "%s = '%s'\n", t, buffer );
6e82b19
-	plp_snprintf( buffer, sizeof(buffer), (t = "%12s"), test1 ); printf( "%s = '%s'\n", t, buffer );
6e82b19
-	plp_snprintf( buffer, sizeof(buffer), (t = "%-12s"), test1 ); printf( "%s = '%s'\n", t, buffer );
6e82b19
-	plp_snprintf( buffer, sizeof(buffer), (t = "%12.2s"), test1 ); printf( "%s = '%s'\n", t, buffer );
6e82b19
-	plp_snprintf( buffer, sizeof(buffer), (t = "%-12.2s"), test1 ); printf( "%s = '%s'\n", t, buffer );
6e82b19
-	plp_snprintf( buffer, sizeof(buffer), (t = "%g"), 1.25 ); printf( "%s = '%s'\n", t, buffer );
6e82b19
-	plp_snprintf( buffer, sizeof(buffer), (t = "%g"), 1.2345 ); printf( "%s = '%s'\n", t, buffer );
6e82b19
-	plp_snprintf( buffer, sizeof(buffer), (t = "%12g"), 1.25 ); printf( "%s = '%s'\n", t, buffer );
6e82b19
-	plp_snprintf( buffer, sizeof(buffer), (t = "%12.2g"), 1.25 ); printf( "%s = '%s'\n", t, buffer );
6e82b19
-	plp_snprintf( buffer, sizeof(buffer), (t = "%0*d"), 6, 1 ); printf( "%s = '%s'\n", t, buffer );
6e82b19
+	buffer[0] = 0;
6e82b19
+	n = snprintf( buffer, 0, (t="test")); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t="errno '%m'")); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%s"), test1 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%12s"), test1 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%-12s"), test1 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%12.2s"), test1 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%-12.2s"), test1 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%g"), 1.25 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%g"), 1.2345 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%12g"), 1.25 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%12.1g"), 1.25 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%12.2g"), 1.25 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%12.3g"), 1.25 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%0*d"), 6, 1 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+#if defined(HAVE_LONG_LONG)
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%llx"), 1, 2, 3, 4 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%llx"), (long long)1, (long long)2 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%qx"), 1, 2, 3, 4 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%qx"), (quad_t)1, (quad_t)2 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+#endif
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "0%x, 0%x"), (char *)(0x01234567), (char *)0, 0, 0, 0); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "0%x, 0%x"), (char *)(0x01234567), (char *)0x89ABCDEF, 0, 0, 0); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "0%x, 0%x"), t, 0, 0, 0, 0); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%f"), 1.25 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%f"), 1.2345 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%12f"), 1.25 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%12.2f"), 1.25 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%f"), 1.0 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%.0f"), 1.0 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%0.0f"), 1.0 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%1.0f"), 1.0 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%1.5f"), 1.0 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
+	n = snprintf( buffer, sizeof(buffer), (t = "%5.5f"), 1.0 ); printf( "[%d] %s = '%s'\n", n, t, buffer );
6e82b19
 	return(0);
6e82b19
 }
6e82b19
 #endif