| 610 | */ |
| 611 | |
| 612 | int /* O - 0 on success, -1 on error */ |
| 613 | cupsFileFlush(cups_file_t *fp) /* I - CUPS file */ |
| 614 | { |
| 615 | ssize_t bytes; /* Bytes to write */ |
| 616 | |
| 617 | |
| 618 | DEBUG_printf(("cupsFileFlush(fp=%p)", (void *)fp)); |
| 619 | |
| 620 | /* |
| 621 | * Range check input... |
| 622 | */ |
| 623 | |
| 624 | if (!fp || fp->mode != 'w') |
| 625 | { |
| 626 | DEBUG_puts("1cupsFileFlush: Attempt to flush a read-only file..."); |
| 627 | return (-1); |
| 628 | } |
| 629 | |
| 630 | bytes = (ssize_t)(fp->ptr - fp->buf); |
| 631 | |
| 632 | DEBUG_printf(("2cupsFileFlush: Flushing " CUPS_LLFMT " bytes...", |
| 633 | CUPS_LLCAST bytes)); |
| 634 | |
| 635 | if (bytes > 0) |
| 636 | { |
| 637 | #ifdef HAVE_LIBZ |
| 638 | if (fp->compressed) |
| 639 | bytes = cups_compress(fp, fp->buf, (size_t)bytes); |
| 640 | else |
| 641 | #endif /* HAVE_LIBZ */ |
| 642 | bytes = cups_write(fp, fp->buf, (size_t)bytes); |
| 643 | |
| 644 | if (bytes < 0) |
| 645 | return (-1); |
| 646 | |
| 647 | fp->ptr = fp->buf; |
| 648 | } |
| 649 | |
| 650 | return (0); |
| 651 | } |
| 652 | |
| 653 | |
| 654 | /* |
no test coverage detected