| 1621 | */ |
| 1622 | |
| 1623 | int /* O - Number of bytes written or -1 on error */ |
| 1624 | cupsFilePuts(cups_file_t *fp, /* I - CUPS file */ |
| 1625 | const char *s) /* I - String to write */ |
| 1626 | { |
| 1627 | ssize_t bytes; /* Bytes to write */ |
| 1628 | |
| 1629 | |
| 1630 | /* |
| 1631 | * Range check input... |
| 1632 | */ |
| 1633 | |
| 1634 | if (!fp || !s || (fp->mode != 'w' && fp->mode != 's')) |
| 1635 | return (-1); |
| 1636 | |
| 1637 | /* |
| 1638 | * Write the string... |
| 1639 | */ |
| 1640 | |
| 1641 | bytes = (ssize_t)strlen(s); |
| 1642 | |
| 1643 | if (fp->mode == 's') |
| 1644 | { |
| 1645 | if (cups_write(fp, s, (size_t)bytes) < 0) |
| 1646 | return (-1); |
| 1647 | |
| 1648 | fp->pos += bytes; |
| 1649 | |
| 1650 | DEBUG_printf(("4cupsFilePuts: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos)); |
| 1651 | |
| 1652 | return ((int)bytes); |
| 1653 | } |
| 1654 | |
| 1655 | if ((fp->ptr + bytes) > fp->end) |
| 1656 | if (cupsFileFlush(fp)) |
| 1657 | return (-1); |
| 1658 | |
| 1659 | fp->pos += bytes; |
| 1660 | |
| 1661 | DEBUG_printf(("4cupsFilePuts: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos)); |
| 1662 | |
| 1663 | if ((size_t)bytes > sizeof(fp->buf)) |
| 1664 | { |
| 1665 | #ifdef HAVE_LIBZ |
| 1666 | if (fp->compressed) |
| 1667 | return ((int)cups_compress(fp, s, (size_t)bytes)); |
| 1668 | else |
| 1669 | #endif /* HAVE_LIBZ */ |
| 1670 | return ((int)cups_write(fp, s, (size_t)bytes)); |
| 1671 | } |
| 1672 | else |
| 1673 | { |
| 1674 | memcpy(fp->ptr, s, (size_t)bytes); |
| 1675 | fp->ptr += bytes; |
| 1676 | |
| 1677 | if (fp->is_stdio && cupsFileFlush(fp)) |
| 1678 | return (-1); |
| 1679 | else |
| 1680 | return ((int)bytes); |