diff options
author | msweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be> | 2008-06-27 20:26:20 +0000 |
---|---|---|
committer | msweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be> | 2008-06-27 20:26:20 +0000 |
commit | 75bd9771f6e44fdd887ee90faac46f403aefc0fc (patch) | |
tree | 354e3067522df9490e905772f73b72bfed8733ae /cups/file.c | |
parent | dd1abb6b5f145c5e5f279d8848b5f3ec161fd227 (diff) | |
download | cups-75bd9771f6e44fdd887ee90faac46f403aefc0fc.tar.gz |
Merge changes from CUPS 1.4svn-r7696.
git-svn-id: svn+ssh://src.apple.com/svn/cups/easysw/current@818 a1ca3aef-8c08-0410-bb20-df032aa958be
Diffstat (limited to 'cups/file.c')
-rw-r--r-- | cups/file.c | 57 |
1 files changed, 47 insertions, 10 deletions
diff --git a/cups/file.c b/cups/file.c index d3726cf53..815e1d3c5 100644 --- a/cups/file.c +++ b/cups/file.c @@ -1,5 +1,5 @@ /* - * "$Id: file.c 6962 2007-09-17 20:35:47Z mike $" + * "$Id: file.c 7672 2008-06-18 22:03:02Z mike $" * * File functions for the Common UNIX Printing System (CUPS). * @@ -119,6 +119,9 @@ struct _cups_file_s /**** CUPS file structure... ****/ Bytef cbuf[4096]; /* (De)compression buffer */ uLong crc; /* (De)compression CRC */ #endif /* HAVE_LIBZ */ + + char *printf_buffer; /* cupsFilePrintf buffer */ + size_t printf_size; /* Size of cupsFilePrintf buffer */ }; @@ -242,6 +245,9 @@ cupsFileClose(cups_file_t *fp) /* I - CUPS file */ mode = fp->mode; is_stdio = fp->is_stdio; + if (fp->printf_buffer) + free(fp->printf_buffer); + free(fp); /* @@ -1111,7 +1117,6 @@ cupsFilePrintf(cups_file_t *fp, /* I - CUPS file */ { va_list ap; /* Argument list */ ssize_t bytes; /* Formatted size */ - char buf[8192]; /* Formatted text */ DEBUG_printf(("cupsFilePrintf(fp=%p, format=\"%s\", ...)\n", fp, format)); @@ -1119,16 +1124,48 @@ cupsFilePrintf(cups_file_t *fp, /* I - CUPS file */ if (!fp || !format || (fp->mode != 'w' && fp->mode != 's')) return (-1); + if (!fp->printf_buffer) + { + /* + * Start with an 1k printf buffer... + */ + + if ((fp->printf_buffer = malloc(1024)) == NULL) + return (-1); + + fp->printf_size = 1024; + } + va_start(ap, format); - bytes = vsnprintf(buf, sizeof(buf), format, ap); + bytes = vsnprintf(fp->printf_buffer, fp->printf_size, format, ap); va_end(ap); - if (bytes >= sizeof(buf)) - return (-1); + if (bytes >= fp->printf_size) + { + /* + * Expand the printf buffer... + */ + + char *temp; /* Temporary buffer pointer */ + + + if (bytes > 65535) + return (-1); + + if ((temp = realloc(fp->printf_buffer, bytes + 1)) == NULL) + return (-1); + + fp->printf_buffer = temp; + fp->printf_size = bytes + 1; + + va_start(ap, format); + bytes = vsnprintf(fp->printf_buffer, fp->printf_size, format, ap); + va_end(ap); + } if (fp->mode == 's') { - if (cups_write(fp, buf, bytes) < 0) + if (cups_write(fp, fp->printf_buffer, bytes) < 0) return (-1); fp->pos += bytes; @@ -1150,14 +1187,14 @@ cupsFilePrintf(cups_file_t *fp, /* I - CUPS file */ { #ifdef HAVE_LIBZ if (fp->compressed) - return (cups_compress(fp, buf, bytes)); + return (cups_compress(fp, fp->printf_buffer, bytes)); else #endif /* HAVE_LIBZ */ - return (cups_write(fp, buf, bytes)); + return (cups_write(fp, fp->printf_buffer, bytes)); } else { - memcpy(fp->ptr, buf, bytes); + memcpy(fp->ptr, fp->printf_buffer, bytes); fp->ptr += bytes; return (bytes); } @@ -2294,5 +2331,5 @@ cups_write(cups_file_t *fp, /* I - CUPS file */ /* - * End of "$Id: file.c 6962 2007-09-17 20:35:47Z mike $". + * End of "$Id: file.c 7672 2008-06-18 22:03:02Z mike $". */ |