]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/snprintf.c
Import CUPS v1.7.1
[thirdparty/cups.git] / cups / snprintf.c
index 86f8c3f63124efab9ee4a64116bb0f372ab53215..4029d2c1d22ce8e2c8cd08cb34fc4bd782c11432 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: snprintf.c 4683 2005-09-21 22:17:44Z mike $"
+ * "$Id: snprintf.c 10996 2013-05-29 11:51:34Z msweet $"
  *
- *   snprintf functions for the Common UNIX Printing System (CUPS).
+ *   snprintf functions for CUPS.
  *
- *   Copyright 1997-2005 by Easy Software Products.
+ *   Copyright 2007-2013 by Apple Inc.
+ *   Copyright 1997-2007 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products and are protected by Federal
- *   copyright law.  Distribution and use rights are outlined in the file
- *   "LICENSE.txt" which should have been included with this file.  If this
- *   file is missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   property of Apple Inc. and are protected by Federal copyright
+ *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ *   which should have been included with this file.  If this file is
+ *   file is missing or damaged, see the license at "http://www.cups.org/".
  *
  *   This file is subject to the Apple OS-Developed Software exception.
  *
@@ -33,9 +24,7 @@
  * Include necessary headers...
  */
 
-#include <stdio.h>
-#include <ctype.h>
-#include "string.h"
+#include "string-private.h"
 
 
 #ifndef HAVE_VSNPRINTF
@@ -59,6 +48,7 @@ _cups_vsnprintf(char       *buffer,   /* O - Output buffer */
   char         tformat[100],           /* Temporary format string for sprintf() */
                *tptr,                  /* Pointer into temporary format */
                temp[1024];             /* Buffer for formatted numbers */
+  size_t       templen;                /* Length of "temp" */
   char         *s;                     /* Pointer to string */
   int          slen;                   /* Length of string */
   int          bytes;                  /* Total number of bytes needed */
@@ -96,7 +86,10 @@ _cups_vsnprintf(char       *buffer,  /* O - Output buffer */
 
       if (*format == '*')
       {
-        // Get width from argument...
+       /*
+        * Get width from argument...
+       */
+
        format ++;
        width = va_arg(ap, int);
 
@@ -125,7 +118,10 @@ _cups_vsnprintf(char       *buffer,        /* O - Output buffer */
 
         if (*format == '*')
        {
-          // Get precision from argument...
+         /*
+         * Get precision from argument...
+         */
+
          format ++;
          prec = va_arg(ap, int);
 
@@ -188,20 +184,21 @@ _cups_vsnprintf(char       *buffer,       /* O - Output buffer */
              break;
 
            sprintf(temp, tformat, va_arg(ap, double));
+           templen = strlen(temp):
 
-            bytes += strlen(temp);
+            bytes += (int)templen;
 
             if (bufptr)
            {
-             if ((bufptr + strlen(temp)) > bufend)
+             if ((bufptr + templen) > bufend)
              {
-               strncpy(bufptr, temp, (size_t)(bufend - bufptr));
+               strlcpy(bufptr, temp, (size_t)(bufend - bufptr));
                bufptr = bufend;
              }
              else
              {
-               strcpy(bufptr, temp);
-               bufptr += strlen(temp);
+               memcpy(bufptr, temp, templen + 1);
+               bufptr += templen;
              }
            }
            break;
@@ -218,20 +215,21 @@ _cups_vsnprintf(char       *buffer,       /* O - Output buffer */
              break;
 
            sprintf(temp, tformat, va_arg(ap, int));
+           templen = strlen(temp):
 
-            bytes += strlen(temp);
+            bytes += (int)templen;
 
            if (bufptr)
            {
-             if ((bufptr + strlen(temp)) > bufend)
+             if ((bufptr + templen) > bufend)
              {
-               strncpy(bufptr, temp, (size_t)(bufend - bufptr));
+               strlcpy(bufptr, temp, (size_t)(bufend - bufptr));
                bufptr = bufend;
              }
              else
              {
-               strcpy(bufptr, temp);
-               bufptr += strlen(temp);
+               memcpy(bufptr, temp, templen + 1);
+               bufptr += templen;
              }
            }
            break;
@@ -241,20 +239,21 @@ _cups_vsnprintf(char       *buffer,       /* O - Output buffer */
              break;
 
            sprintf(temp, tformat, va_arg(ap, void *));
+           templen = strlen(temp):
 
-            bytes += strlen(temp);
+            bytes += (int)templen;
 
            if (bufptr)
            {
-             if ((bufptr + strlen(temp)) > bufend)
+             if ((bufptr + templen) > bufend)
              {
-               strncpy(bufptr, temp, (size_t)(bufend - bufptr));
+               strlcpy(bufptr, temp, (size_t)(bufend - bufptr));
                bufptr = bufend;
              }
              else
              {
-               strcpy(bufptr, temp);
-               bufptr += strlen(temp);
+               memcpy(bufptr, temp, templen + 1);
+               bufptr += templen;
              }
            }
            break;
@@ -269,7 +268,7 @@ _cups_vsnprintf(char       *buffer, /* O - Output buffer */
              else
              {
                if ((bufptr + width) > bufend)
-                 width = bufend - bufptr;
+                 width = (int)(bufend - bufptr);
 
                memcpy(bufptr, va_arg(ap, char *), (size_t)width);
                bufptr += width;
@@ -281,7 +280,7 @@ _cups_vsnprintf(char       *buffer, /* O - Output buffer */
            if ((s = va_arg(ap, char *)) == NULL)
              s = "(null)";
 
-           slen = strlen(s);
+           slen = (int)strlen(s);
            if (slen > width && prec != width)
              width = slen;
 
@@ -290,20 +289,20 @@ _cups_vsnprintf(char       *buffer,       /* O - Output buffer */
            if (bufptr)
            {
              if ((bufptr + width) > bufend)
-               width = bufend - bufptr;
+               width = (int)(bufend - bufptr);
 
               if (slen > width)
                slen = width;
 
              if (sign == '-')
              {
-               strncpy(bufptr, s, (size_t)slen);
+               memcpy(bufptr, s, (size_t)slen);
                memset(bufptr + slen, ' ', (size_t)(width - slen));
              }
              else
              {
                memset(bufptr, ' ', (size_t)(width - slen));
-               strncpy(bufptr + width - slen, s, (size_t)slen);
+               memcpy(bufptr + width - slen, s, (size_t)slen);
              }
 
              bufptr += width;
@@ -362,6 +361,6 @@ _cups_snprintf(char       *buffer,  /* O - Output buffer */
 
 
 /*
- * End of "$Id: snprintf.c 4683 2005-09-21 22:17:44Z mike $".
+ * End of "$Id: snprintf.c 10996 2013-05-29 11:51:34Z msweet $".
  */