| 590 | */ |
| 591 | |
| 592 | unsigned /* O - 1 on success, 0 on fail */ |
| 593 | _cupsRasterReadHeader( |
| 594 | cups_raster_t *r) /* I - Raster stream */ |
| 595 | { |
| 596 | size_t len; /* Length for read/swap */ |
| 597 | |
| 598 | |
| 599 | DEBUG_printf(("3_cupsRasterReadHeader(r=%p), r->mode=%s", (void *)r, r ? cups_modes[r->mode] : "")); |
| 600 | |
| 601 | if (r == NULL || r->mode != CUPS_RASTER_READ) |
| 602 | return (0); |
| 603 | |
| 604 | DEBUG_printf(("4_cupsRasterReadHeader: r->iocount=" CUPS_LLFMT, CUPS_LLCAST r->iocount)); |
| 605 | |
| 606 | memset(&(r->header), 0, sizeof(r->header)); |
| 607 | |
| 608 | /* |
| 609 | * Read the header... |
| 610 | */ |
| 611 | |
| 612 | switch (r->sync) |
| 613 | { |
| 614 | default : |
| 615 | /* |
| 616 | * Get the length of the raster header... |
| 617 | */ |
| 618 | |
| 619 | if (r->sync == CUPS_RASTER_SYNCv1 || r->sync == CUPS_RASTER_REVSYNCv1) |
| 620 | len = sizeof(cups_page_header_t); |
| 621 | else |
| 622 | len = sizeof(cups_page_header2_t); |
| 623 | |
| 624 | DEBUG_printf(("4_cupsRasterReadHeader: len=%d", (int)len)); |
| 625 | |
| 626 | /* |
| 627 | * Read it... |
| 628 | */ |
| 629 | |
| 630 | if (cups_raster_read(r, (unsigned char *)&(r->header), len) < (ssize_t)len) |
| 631 | { |
| 632 | DEBUG_printf(("4_cupsRasterReadHeader: EOF, r->iocount=" CUPS_LLFMT, CUPS_LLCAST r->iocount)); |
| 633 | return (0); |
| 634 | } |
| 635 | |
| 636 | /* |
| 637 | * Swap bytes as needed... |
| 638 | */ |
| 639 | |
| 640 | if (r->swapped) |
| 641 | { |
| 642 | unsigned *s, /* Current word */ |
| 643 | temp; /* Temporary copy */ |
| 644 | |
| 645 | |
| 646 | DEBUG_puts("4_cupsRasterReadHeader: Swapping header bytes."); |
| 647 | |
| 648 | for (len = 81, s = &(r->header.AdvanceDistance); |
| 649 | len > 0; |
no test coverage detected