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

Function cupsFileRead

cups/file.c:1691–1763  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1689 */
1690
1691ssize_t /* O - Number of bytes read or -1 on error */
1692cupsFileRead(cups_file_t *fp, /* I - CUPS file */
1693 char *buf, /* O - Buffer */
1694 size_t bytes) /* I - Number of bytes to read */
1695{
1696 size_t total; /* Total bytes read */
1697 ssize_t count; /* Bytes read */
1698
1699
1700 DEBUG_printf(("2cupsFileRead(fp=%p, buf=%p, bytes=" CUPS_LLFMT ")", (void *)fp, (void *)buf, CUPS_LLCAST bytes));
1701
1702 /*
1703 * Range check input...
1704 */
1705
1706 if (!fp || !buf || (fp->mode != 'r' && fp->mode != 's'))
1707 return (-1);
1708
1709 if (bytes == 0)
1710 return (0);
1711
1712 if (fp->eof)
1713 {
1714 DEBUG_puts("5cupsFileRead: End-of-file!");
1715 return (-1);
1716 }
1717
1718 /*
1719 * Loop until all bytes are read...
1720 */
1721
1722 total = 0;
1723 while (bytes > 0)
1724 {
1725 if (fp->ptr >= fp->end)
1726 if (cups_fill(fp) <= 0)
1727 {
1728 DEBUG_printf(("4cupsFileRead: cups_fill() returned -1, total="
1729 CUPS_LLFMT, CUPS_LLCAST total));
1730
1731 if (total > 0)
1732 return ((ssize_t)total);
1733 else
1734 return (-1);
1735 }
1736
1737 count = (ssize_t)(fp->end - fp->ptr);
1738 if (count > (ssize_t)bytes)
1739 count = (ssize_t)bytes;
1740
1741 memcpy(buf, fp->ptr,(size_t) count);
1742 fp->ptr += count;
1743 fp->pos += count;
1744
1745 DEBUG_printf(("4cupsFileRead: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos));
1746
1747 /*
1748 * Update the counts for the last read...

Callers 15

do_testFunction · 0.85
cat_tarFunction · 0.85
load_ppds_datFunction · 0.85
read_tarFunction · 0.85
install_cupsd_confFunction · 0.85
copy_fileFunction · 0.85
mimeFileTypeFunction · 0.85
mime_check_rulesFunction · 0.85
get_utf16Function · 0.85
backend_init_suppliesFunction · 0.85
do_config_serverFunction · 0.85
copy_bytesFunction · 0.85

Calls 1

cups_fillFunction · 0.85

Tested by 5

print_fileFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
random_testsFunction · 0.68
read_write_testsFunction · 0.68