MCPcopy Create free account
hub / github.com/OpenPrinting/cups / cupsFilePuts

Function cupsFilePuts

cups/file.c:1623–1682  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1621 */
1622
1623int /* O - Number of bytes written or -1 on error */
1624cupsFilePuts(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);

Callers 15

do_testFunction · 0.85
pause_messageFunction · 0.85
print_attrFunction · 0.85
print_csvFunction · 0.85
print_ippserver_attrFunction · 0.85
print_json_attrFunction · 0.85
print_json_stringFunction · 0.85
print_lineFunction · 0.85
print_xml_headerFunction · 0.85
print_xml_stringFunction · 0.85
print_xml_trailerFunction · 0.85

Calls 3

cups_writeFunction · 0.85
cupsFileFlushFunction · 0.85
cups_compressFunction · 0.85

Tested by 2

mainFunction · 0.68
read_write_testsFunction · 0.68