*
* Raster file routines for CUPS.
*
- * Copyright 2007-2014 by Apple Inc.
+ * Copyright 2007-2015 by Apple Inc.
* Copyright 1997-2006 by Easy Software Products.
*
* This file is part of the CUPS Imaging library.
*bufptr, /* Current (read) position in buffer */
*bufend; /* End of current (read) buffer */
size_t bufsize; /* Buffer size */
+#ifdef DEBUG
+ size_t iocount; /* Number of bytes read/written */
+#endif /* DEBUG */
};
static unsigned cups_raster_read_header(cups_raster_t *r);
static ssize_t cups_raster_read(cups_raster_t *r, unsigned char *buf,
size_t bytes);
-static void cups_raster_update(cups_raster_t *r);
+static int cups_raster_update(cups_raster_t *r);
static ssize_t cups_raster_write(cups_raster_t *r,
const unsigned char *pixels);
static ssize_t cups_read_fd(void *ctx, unsigned char *buf, size_t bytes);
}
+/*
+ * 'cupsRasterInitPWGHeader()' - Initialize a page header for PWG Raster output.
+ *
+ * The "media" argument specifies the media to use.
+ *
+ * The "type" argument specifies a "pwg-raster-document-type-supported" value
+ * that controls the color space and bit depth of the raster data.
+ *
+ * The "xres" and "yres" arguments specify the raster resolution in dots per
+ * inch.
+ *
+ * The "sheet_back" argument specifies a "pwg-raster-document-sheet-back" value
+ * to apply for the back side of a page. Pass @code NULL@ for the front side.
+ *
+ * @since CUPS 2.2@
+ */
+
+int /* O - 1 on success, 0 on failure */
+cupsRasterInitPWGHeader(
+ cups_page_header2_t *h, /* I - Page header */
+ pwg_media_t *media, /* I - PWG media information */
+ const char *type, /* I - PWG raster type string */
+ int xdpi, /* I - Cross-feed direction (horizontal) resolution */
+ int ydpi, /* I - Feed direction (vertical) resolution */
+ const char *sides, /* I - IPP "sides" option value */
+ const char *sheet_back) /* I - Transform for back side or @code NULL@ for none */
+{
+ if (!h || !media || !type || xdpi <= 0 || ydpi <= 0)
+ {
+ _cupsRasterAddError("%s", strerror(EINVAL));
+ return (0);
+ }
+
+ /*
+ * Initialize the page header...
+ */
+
+ memset(h, 0, sizeof(cups_page_header2_t));
+
+ strlcpy(h->cupsPageSizeName, media->pwg, sizeof(h->cupsPageSizeName));
+
+ h->PageSize[0] = (unsigned)(72 * media->width / 2540);
+ h->PageSize[1] = (unsigned)(72 * media->length / 2540);
+
+ /* This never gets written but is needed for some applications */
+ h->cupsPageSize[0] = 72.0f * media->width / 2540.0f;
+ h->cupsPageSize[1] = 72.0f * media->length / 2540.0f;
+
+ h->ImagingBoundingBox[2] = h->PageSize[0];
+ h->ImagingBoundingBox[3] = h->PageSize[1];
+
+ h->HWResolution[0] = (unsigned)xdpi;
+ h->HWResolution[1] = (unsigned)ydpi;
+
+ h->cupsWidth = (unsigned)(media->width * xdpi / 2540);
+ h->cupsHeight = (unsigned)(media->length * ydpi / 2540);
+
+ if (h->cupsWidth > 0x00ffffff || h->cupsHeight > 0x00ffffff)
+ {
+ _cupsRasterAddError("Raster dimensions too large.");
+ return (0);
+ }
+
+ h->cupsInteger[CUPS_RASTER_PWG_ImageBoxRight] = h->cupsWidth;
+ h->cupsInteger[CUPS_RASTER_PWG_ImageBoxBottom] = h->cupsHeight;
+
+ /*
+ * Colorspace and bytes per line...
+ */
+
+ if (!strcmp(type, "adobe-rgb_8"))
+ {
+ h->cupsBitsPerColor = 8;
+ h->cupsBitsPerPixel = 24;
+ h->cupsColorSpace = CUPS_CSPACE_ADOBERGB;
+ }
+ else if (!strcmp(type, "adobe-rgb_16"))
+ {
+ h->cupsBitsPerColor = 16;
+ h->cupsBitsPerPixel = 48;
+ h->cupsColorSpace = CUPS_CSPACE_ADOBERGB;
+ }
+ else if (!strcmp(type, "black_1"))
+ {
+ h->cupsBitsPerColor = 1;
+ h->cupsBitsPerPixel = 1;
+ h->cupsColorSpace = CUPS_CSPACE_K;
+ }
+ else if (!strcmp(type, "black_8"))
+ {
+ h->cupsBitsPerColor = 8;
+ h->cupsBitsPerPixel = 8;
+ h->cupsColorSpace = CUPS_CSPACE_K;
+ }
+ else if (!strcmp(type, "black_16"))
+ {
+ h->cupsBitsPerColor = 16;
+ h->cupsBitsPerPixel = 16;
+ h->cupsColorSpace = CUPS_CSPACE_K;
+ }
+ else if (!strcmp(type, "cmyk_8"))
+ {
+ h->cupsBitsPerColor = 8;
+ h->cupsBitsPerPixel = 32;
+ h->cupsColorSpace = CUPS_CSPACE_CMYK;
+ }
+ else if (!strcmp(type, "cmyk_16"))
+ {
+ h->cupsBitsPerColor = 16;
+ h->cupsBitsPerPixel = 64;
+ h->cupsColorSpace = CUPS_CSPACE_CMYK;
+ }
+ else if (!strncmp(type, "device", 6) && type[6] >= '1' && type[6] <= '9')
+ {
+ int ncolors, bits; /* Number of colors and bits */
+
+
+ if (sscanf(type, "device%d_%d", &ncolors, &bits) != 2 || ncolors > 15 || (bits != 8 && bits != 16))
+ {
+ _cupsRasterAddError("Unsupported raster type \'%s\'.", type);
+ return (0);
+ }
+
+ h->cupsBitsPerColor = (unsigned)bits;
+ h->cupsBitsPerPixel = (unsigned)(ncolors * bits);
+ h->cupsColorSpace = (cups_cspace_t)(CUPS_CSPACE_DEVICE1 + ncolors - 1);
+ }
+ else if (!strcmp(type, "rgb_8"))
+ {
+ h->cupsBitsPerColor = 8;
+ h->cupsBitsPerPixel = 24;
+ h->cupsColorSpace = CUPS_CSPACE_RGB;
+ }
+ else if (!strcmp(type, "rgb_16"))
+ {
+ h->cupsBitsPerColor = 16;
+ h->cupsBitsPerPixel = 48;
+ h->cupsColorSpace = CUPS_CSPACE_RGB;
+ }
+ else if (!strcmp(type, "sgray_1"))
+ {
+ h->cupsBitsPerColor = 1;
+ h->cupsBitsPerPixel = 1;
+ h->cupsColorSpace = CUPS_CSPACE_SW;
+ }
+ else if (!strcmp(type, "sgray_8"))
+ {
+ h->cupsBitsPerColor = 8;
+ h->cupsBitsPerPixel = 8;
+ h->cupsColorSpace = CUPS_CSPACE_SW;
+ }
+ else if (!strcmp(type, "sgray_16"))
+ {
+ h->cupsBitsPerColor = 16;
+ h->cupsBitsPerPixel = 16;
+ h->cupsColorSpace = CUPS_CSPACE_SW;
+ }
+ else if (!strcmp(type, "srgb_8"))
+ {
+ h->cupsBitsPerColor = 8;
+ h->cupsBitsPerPixel = 24;
+ h->cupsColorSpace = CUPS_CSPACE_SRGB;
+ }
+ else if (!strcmp(type, "srgb_16"))
+ {
+ h->cupsBitsPerColor = 16;
+ h->cupsBitsPerPixel = 48;
+ h->cupsColorSpace = CUPS_CSPACE_SRGB;
+ }
+ else
+ {
+ _cupsRasterAddError("Unsupported raster type \'%s\'.", type);
+ return (0);
+ }
+
+ h->cupsColorOrder = CUPS_ORDER_CHUNKED;
+ h->cupsNumColors = h->cupsBitsPerPixel / h->cupsBitsPerColor;
+ h->cupsBytesPerLine = (h->cupsWidth * h->cupsBitsPerPixel + 7) / 8;
+
+ /*
+ * Duplex support...
+ */
+
+ h->cupsInteger[CUPS_RASTER_PWG_CrossFeedTransform] = 1;
+ h->cupsInteger[CUPS_RASTER_PWG_FeedTransform] = 1;
+
+ if (sides)
+ {
+ if (!strcmp(sides, "two-sided-long-edge"))
+ {
+ h->Duplex = 1;
+ }
+ else if (!strcmp(sides, "two-sided-short-edge"))
+ {
+ h->Duplex = 1;
+ h->Tumble = 1;
+ }
+ else if (strcmp(sides, "one-sided"))
+ {
+ _cupsRasterAddError("Unsupported sides value \'%s\'.", sides);
+ return (0);
+ }
+
+ if (sheet_back)
+ {
+ if (!strcmp(sheet_back, "flipped"))
+ {
+ if (h->Tumble)
+ h->cupsInteger[CUPS_RASTER_PWG_CrossFeedTransform] = 0xffffffffU;
+ else
+ h->cupsInteger[CUPS_RASTER_PWG_FeedTransform] = 0xffffffffU;
+ }
+ else if (!strcmp(sheet_back, "manual-tumble"))
+ {
+ if (h->Tumble)
+ {
+ h->cupsInteger[CUPS_RASTER_PWG_CrossFeedTransform] = 0xffffffffU;
+ h->cupsInteger[CUPS_RASTER_PWG_FeedTransform] = 0xffffffffU;
+ }
+ }
+ else if (!strcmp(sheet_back, "rotated"))
+ {
+ if (!h->Tumble)
+ {
+ h->cupsInteger[CUPS_RASTER_PWG_CrossFeedTransform] = 0xffffffffU;
+ h->cupsInteger[CUPS_RASTER_PWG_FeedTransform] = 0xffffffffU;
+ }
+ }
+ else if (strcmp(sheet_back, "normal"))
+ {
+ _cupsRasterAddError("Unsupported sheet_back value \'%s\'.", sheet_back);
+ return (0);
+ }
+ }
+ }
+
+ return (1);
+}
+
+
/*
* 'cupsRasterOpen()' - Open a raster stream using a file descriptor.
*
r->sync == CUPS_RASTER_REVSYNCv2)
r->swapped = 1;
- DEBUG_printf(("r->swapped=%d, r->sync=%08x\n", r->swapped, r->sync));
+ DEBUG_printf(("1cupsRasterOpenIO: r->swapped=%d, r->sync=%08x\n", r->swapped, r->sync));
}
else
{
*/
if (!cups_raster_read_header(r))
+ {
+ memset(h, 0, sizeof(cups_page_header_t));
return (0);
+ }
/*
* Copy the header to the user-supplied buffer...
* Get the raster header...
*/
+ DEBUG_printf(("cupsRasterReadHeader2(r=%p, h=%p)", (void *)r, (void *)h));
+
if (!cups_raster_read_header(r))
+ {
+ memset(h, 0, sizeof(cups_page_header2_t));
return (0);
+ }
/*
* Copy the header to the user-supplied buffer...
unsigned count; /* Repetition count */
+ DEBUG_printf(("cupsRasterReadPixels(r=%p, p=%p, len=%u)", (void *)r, (void *)p, len));
+
if (r == NULL || r->mode != CUPS_RASTER_READ || r->remaining == 0 ||
r->header.cupsBytesPerLine == 0)
+ {
+ DEBUG_puts("1cupsRasterReadPixels: Returning 0.");
return (0);
+ }
+
+ DEBUG_printf(("1cupsRasterReadPixels: compressed=%d, remaining=%u", r->compressed, r->remaining));
if (!r->compressed)
{
r->remaining -= len / r->header.cupsBytesPerLine;
if (cups_raster_io(r, p, len) < (ssize_t)len)
+ {
+ DEBUG_puts("1cupsRasterReadPixels: Read error, returning 0.");
return (0);
+ }
/*
* Swap bytes as needed...
* Return...
*/
+ DEBUG_printf(("1cupsRasterReadPixels: Returning %u", len));
+
return (len);
}
*/
if (!cups_raster_read(r, &byte, 1))
+ {
+ DEBUG_puts("1cupsRasterReadPixels: Read error, returning 0.");
return (0);
+ }
r->count = (unsigned)byte + 1;
*/
if (!cups_raster_read(r, &byte, 1))
+ {
+ DEBUG_puts("1cupsRasterReadPixels: Read error, returning 0.");
return (0);
+ }
if (byte & 128)
{
count = (unsigned)bytes;
if (!cups_raster_read(r, temp, count))
+ {
+ DEBUG_puts("1cupsRasterReadPixels: Read error, returning 0.");
return (0);
+ }
temp += count;
bytes -= count;
bytes -= count;
if (!cups_raster_read(r, temp, r->bpp))
+ {
+ DEBUG_puts("1cupsRasterReadPixels: Read error, returning 0.");
return (0);
+ }
temp += r->bpp;
count -= r->bpp;
p += bytes;
}
+ DEBUG_printf(("1cupsRasterReadPixels: Returning %u", len));
+
return (len);
}
memset(&(r->header), 0, sizeof(r->header));
memcpy(&(r->header), h, sizeof(cups_page_header_t));
- cups_raster_update(r);
+ if (!cups_raster_update(r))
+ return (0);
/*
* Write the raster header...
fh.cupsInteger[15] = htonl(r->header.cupsInteger[15]);
/* VendorLength */
- void *p = fh.cupsReal; /* Bypass bogus compiler warning */
- memcpy(p, r->header.cupsReal, sizeof(fh.cupsReal) + sizeof(fh.cupsString));
+ void *dst = fh.cupsReal; /* Bypass bogus compiler warning */
+ void *src = r->header.cupsReal;
+ memcpy(dst, src, sizeof(fh.cupsReal) + sizeof(fh.cupsString));
/* VendorData */
strlcpy(fh.cupsRenderingIntent, r->header.cupsRenderingIntent,
memcpy(&(r->header), h, sizeof(cups_page_header2_t));
- cups_raster_update(r);
+ if (!cups_raster_update(r))
+ return (0);
/*
* Write the raster header...
fh.cupsInteger[0] = htonl(r->header.cupsInteger[0]);
fh.cupsInteger[1] = htonl(r->header.cupsInteger[1]);
fh.cupsInteger[2] = htonl(r->header.cupsInteger[2]);
- fh.cupsInteger[3] = htonl((unsigned)(r->header.cupsImagingBBox[0] *
- r->header.HWResolution[0]));
- fh.cupsInteger[4] = htonl((unsigned)(r->header.cupsImagingBBox[1] *
- r->header.HWResolution[1]));
- fh.cupsInteger[5] = htonl((unsigned)(r->header.cupsImagingBBox[2] *
- r->header.HWResolution[0]));
- fh.cupsInteger[6] = htonl((unsigned)(r->header.cupsImagingBBox[3] *
- r->header.HWResolution[1]));
+ fh.cupsInteger[3] = htonl((unsigned)(r->header.cupsImagingBBox[0] * r->header.HWResolution[0] / 72.0));
+ fh.cupsInteger[4] = htonl((unsigned)(r->header.cupsImagingBBox[1] * r->header.HWResolution[1] / 72.0));
+ fh.cupsInteger[5] = htonl((unsigned)(r->header.cupsImagingBBox[2] * r->header.HWResolution[0] / 72.0));
+ fh.cupsInteger[6] = htonl((unsigned)(r->header.cupsImagingBBox[3] * r->header.HWResolution[1] / 72.0));
fh.cupsInteger[7] = htonl(0xffffff);
return (cups_raster_io(r, (unsigned char *)&fh, sizeof(fh)) == sizeof(fh));
unsigned remaining; /* Bytes remaining */
- DEBUG_printf(("cupsRasterWritePixels(r=%p, p=%p, len=%u), remaining=%u\n",
- r, p, len, r->remaining));
+ DEBUG_printf(("cupsRasterWritePixels(r=%p, p=%p, len=%u), remaining=%u", (void *)r, (void *)p, len, r->remaining));
if (r == NULL || r->mode == CUPS_RASTER_READ || r->remaining == 0)
return (0);
* Write the byte-swapped buffer...
*/
- return ((unsigned)cups_raster_io(r, r->buffer, len));
+ bytes = cups_raster_io(r, r->buffer, len);
}
else
- return ((unsigned)cups_raster_io(r, p, len));
+ bytes = cups_raster_io(r, p, len);
+
+ if (bytes < len)
+ return (0);
+ else
+ return (len);
}
/*
if (memcmp(p, r->pcurrent, (size_t)bytes))
{
- if (!cups_raster_write(r, r->pixels))
+ if (cups_raster_write(r, r->pixels) <= 0)
return (0);
r->count = 0;
r->remaining --;
if (r->remaining == 0)
- return ((unsigned)cups_raster_write(r, r->pixels));
+ {
+ if (cups_raster_write(r, r->pixels) <= 0)
+ return (0);
+ else
+ return (len);
+ }
else if (r->count == 256)
{
- if (cups_raster_write(r, r->pixels) == 0)
+ if (cups_raster_write(r, r->pixels) <= 0)
return (0);
r->count = 0;
r->remaining --;
if (r->remaining == 0)
- return ((unsigned)cups_raster_write(r, r->pixels));
+ {
+ if (cups_raster_write(r, r->pixels) <= 0)
+ return (0);
+ }
}
}
}
size_t len; /* Length for read/swap */
+ DEBUG_printf(("3cups_raster_read_header(r=%p), r->mode=%d", (void *)r, r ? r->mode : 0));
+
if (r == NULL || r->mode != CUPS_RASTER_READ)
return (0);
+ DEBUG_printf(("4cups_raster_read_header: r->iocount=" CUPS_LLFMT, CUPS_LLCAST r->iocount));
+
/*
* Get the length of the raster header...
*/
else
len = sizeof(cups_page_header2_t);
+ DEBUG_printf(("4cups_raster_read_header: len=%d", (int)len));
+
/*
* Read the header...
*/
memset(&(r->header), 0, sizeof(r->header));
if (cups_raster_read(r, (unsigned char *)&(r->header), len) < (ssize_t)len)
+ {
+ DEBUG_printf(("4cups_raster_read_header: EOF, r->iocount=" CUPS_LLFMT, CUPS_LLCAST r->iocount));
return (0);
+ }
/*
* Swap bytes as needed...
temp; /* Temporary copy */
- DEBUG_puts("Swapping header bytes...");
+ DEBUG_puts("4cups_raster_read_header: Swapping header bytes.");
for (len = 81, s = &(r->header.AdvanceDistance);
len > 0;
len --, s ++)
{
- DEBUG_printf(("%08x =>", *s));
-
temp = *s;
*s = ((temp & 0xff) << 24) |
((temp & 0xff00) << 8) |
((temp & 0xff0000) >> 8) |
((temp & 0xff000000) >> 24);
- DEBUG_printf((" %08x\n", *s));
+ DEBUG_printf(("4cups_raster_read_header: %08x => %08x", temp, *s));
}
}
* Update the header and row count...
*/
- cups_raster_update(r);
+ if (!cups_raster_update(r))
+ return (0);
+
+ DEBUG_printf(("4cups_raster_read_header: cupsBitsPerPixel=%u, cupsBitsPerColor=%u, cupsBytesPerLine=%u, cupsWidth=%u, cupsHeight=%u, r->bpp=%d", r->header.cupsBitsPerPixel, r->header.cupsBitsPerColor, r->header.cupsBytesPerLine, r->header.cupsWidth, r->header.cupsHeight, r->bpp));
- return (r->header.cupsBytesPerLine != 0 && r->header.cupsHeight != 0);
+ return (r->header.cupsBitsPerPixel > 0 && r->header.cupsBitsPerPixel <= 240 && r->header.cupsBitsPerColor > 0 && r->header.cupsBitsPerColor <= 16 && r->header.cupsBytesPerLine > 0 && r->header.cupsBytesPerLine <= 0x7fffffff && r->header.cupsHeight != 0 && (r->header.cupsBytesPerLine % r->bpp) == 0);
}
total; /* Total bytes read/written */
- DEBUG_printf(("4cups_raster_io(r=%p, buf=%p, bytes=" CUPS_LLFMT ")", r, buf, CUPS_LLCAST bytes));
+ DEBUG_printf(("5cups_raster_io(r=%p, buf=%p, bytes=" CUPS_LLFMT ")", (void *)r, (void *)buf, CUPS_LLCAST bytes));
for (total = 0; total < (ssize_t)bytes; total += count, buf += count)
{
count = (*r->iocb)(r->ctx, buf, bytes - (size_t)total);
- DEBUG_printf(("5cups_raster_io: count=%d, total=%d", (int)count,
- (int)total));
+ DEBUG_printf(("6cups_raster_io: count=%d, total=%d", (int)count, (int)total));
if (count == 0)
+ {
+ DEBUG_puts("6cups_raster_io: Returning 0.");
return (0);
+ }
else if (count < 0)
+ {
+ DEBUG_puts("6cups_raster_io: Returning -1 on error.");
return (-1);
+ }
+
+#ifdef DEBUG
+ r->iocount += (size_t)count;
+#endif /* DEBUG */
}
+ DEBUG_printf(("6cups_raster_io: Returning " CUPS_LLFMT ".", CUPS_LLCAST total));
+
return (total);
}
total; /* Total bytes read */
- DEBUG_printf(("cups_raster_read(r=%p, buf=%p, bytes=" CUPS_LLFMT ")\n", r, buf, CUPS_LLCAST bytes));
+ DEBUG_printf(("5cups_raster_read(r=%p, buf=%p, bytes=" CUPS_LLFMT ")", (void *)r, (void *)buf, CUPS_LLCAST bytes));
if (!r->compressed)
return (cups_raster_io(r, buf, bytes));
*/
count = (ssize_t)(2 * r->header.cupsBytesPerLine);
+ if (count < 65536)
+ count = 65536;
if ((size_t)count > r->bufsize)
{
{
count = (ssize_t)bytes - total;
- DEBUG_printf(("count=" CUPS_LLFMT ", remaining=" CUPS_LLFMT ", buf=%p, bufptr=%p, bufend=%p...\n", CUPS_LLCAST count, CUPS_LLCAST remaining, buf, r->bufptr, r->bufend));
+ DEBUG_printf(("6cups_raster_read: count=" CUPS_LLFMT ", remaining=" CUPS_LLFMT ", buf=%p, bufptr=%p, bufend=%p", CUPS_LLCAST count, CUPS_LLCAST remaining, (void *)buf, (void *)r->bufptr, (void *)r->bufend));
if (remaining == 0)
{
r->bufptr = r->buffer;
r->bufend = r->buffer + remaining;
+
+#ifdef DEBUG
+ r->iocount += (size_t)remaining;
+#endif /* DEBUG */
}
else
{
if (count <= 0)
return (0);
+#ifdef DEBUG
+ r->iocount += (size_t)count;
+#endif /* DEBUG */
+
continue;
}
}
}
}
+ DEBUG_printf(("6cups_raster_read: Returning %ld", (long)total));
+
return (total);
}
* current page.
*/
-static void
+static int /* O - 1 on success, 0 on failure */
cups_raster_update(cups_raster_t *r) /* I - Raster stream */
{
if (r->sync == CUPS_RASTER_SYNCv1 || r->sync == CUPS_RASTER_REVSYNCv1 ||
r->header.cupsNumColors = r->header.cupsColorSpace -
CUPS_CSPACE_DEVICE1 + 1;
break;
+
+ default :
+ /* Unknown color space */
+ return (0);
}
}
else
r->bpp = (r->header.cupsBitsPerColor + 7) / 8;
+ if (r->bpp == 0)
+ r->bpp = 1;
+
/*
* Set the number of remaining rows...
*/
if (r->pixels != NULL)
free(r->pixels);
- r->pixels = calloc(r->header.cupsBytesPerLine, 1);
+ if ((r->pixels = calloc(r->header.cupsBytesPerLine, 1)) == NULL)
+ {
+ r->pcurrent = NULL;
+ r->pend = NULL;
+ r->count = 0;
+
+ return (0);
+ }
+
r->pcurrent = r->pixels;
r->pend = r->pixels + r->header.cupsBytesPerLine;
r->count = 0;
}
+
+ return (1);
}
count; /* Count */
- DEBUG_printf(("cups_raster_write(r=%p, pixels=%p)\n", r, pixels));
+ DEBUG_printf(("3cups_raster_write(r=%p, pixels=%p)", (void *)r, (void *)pixels));
/*
* Allocate a write buffer as needed...
*/
count = r->header.cupsBytesPerLine * 2;
+ if (count < 65536)
+ count = 65536;
+
if ((size_t)count > r->bufsize)
{
if (r->buffer)
wptr = malloc(count);
if (!wptr)
+ {
+ DEBUG_printf(("4cups_raster_write: Unable to allocate " CUPS_LLFMT " bytes for raster buffer: %s", CUPS_LLCAST count, strerror(errno)));
return (-1);
+ }
r->buffer = wptr;
r->bufsize = count;
}
}
+ DEBUG_printf(("4cups_raster_write: Writing " CUPS_LLFMT " bytes.", CUPS_LLCAST (wptr - r->buffer)));
+
return (cups_raster_io(r, r->buffer, (size_t)(wptr - r->buffer)));
}
while ((count = read(fd, buf, bytes)) < 0)
#endif /* WIN32 */
if (errno != EINTR && errno != EAGAIN)
+ {
+ DEBUG_printf(("4cups_read_fd: %s", strerror(errno)));
return (-1);
+ }
+
+ DEBUG_printf(("4cups_read_fd: Returning %d bytes.", (int)count));
return (count);
}
while ((count = write(fd, buf, bytes)) < 0)
#endif /* WIN32 */
if (errno != EINTR && errno != EAGAIN)
+ {
+ DEBUG_printf(("4cups_write_fd: %s", strerror(errno)));
return (-1);
+ }
return (count);
}