| 1771 | */ |
| 1772 | |
| 1773 | off_t /* O - New file position or -1 on error */ |
| 1774 | cupsFileRewind(cups_file_t *fp) /* I - CUPS file */ |
| 1775 | { |
| 1776 | /* |
| 1777 | * Range check input... |
| 1778 | */ |
| 1779 | |
| 1780 | DEBUG_printf(("cupsFileRewind(fp=%p)", (void *)fp)); |
| 1781 | |
| 1782 | if (!fp || fp->mode != 'r') |
| 1783 | return (-1); |
| 1784 | |
| 1785 | DEBUG_printf(("2cupsFileRewind: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos)); |
| 1786 | |
| 1787 | /* |
| 1788 | * Handle special cases... |
| 1789 | */ |
| 1790 | |
| 1791 | if (fp->bufpos == 0) |
| 1792 | { |
| 1793 | /* |
| 1794 | * No seeking necessary... |
| 1795 | */ |
| 1796 | |
| 1797 | fp->pos = 0; |
| 1798 | |
| 1799 | if (fp->ptr) |
| 1800 | { |
| 1801 | fp->ptr = fp->buf; |
| 1802 | fp->eof = 0; |
| 1803 | } |
| 1804 | |
| 1805 | DEBUG_printf(("2cupsFileRewind: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos)); |
| 1806 | |
| 1807 | return (0); |
| 1808 | } |
| 1809 | |
| 1810 | /* |
| 1811 | * Otherwise, seek in the file and cleanup any compression buffers... |
| 1812 | */ |
| 1813 | |
| 1814 | #ifdef HAVE_LIBZ |
| 1815 | if (fp->compressed) |
| 1816 | { |
| 1817 | inflateEnd(&fp->stream); |
| 1818 | fp->compressed = 0; |
| 1819 | } |
| 1820 | #endif /* HAVE_LIBZ */ |
| 1821 | |
| 1822 | if (lseek(fp->fd, 0, SEEK_SET)) |
| 1823 | { |
| 1824 | DEBUG_printf(("1cupsFileRewind: lseek failed: %s", strerror(errno))); |
| 1825 | return (-1); |
| 1826 | } |
| 1827 | |
| 1828 | fp->bufpos = 0; |
| 1829 | fp->pos = 0; |
| 1830 | fp->ptr = NULL; |
no outgoing calls