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