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

Function cupsFileSeek

cups/file.c:1846–1990  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1844 */
1845
1846off_t /* O - New file position or -1 on error */
1847cupsFileSeek(cups_file_t *fp, /* I - CUPS file */
1848 off_t pos) /* I - Position in file */
1849{
1850 ssize_t bytes; /* Number bytes in buffer */
1851
1852
1853 DEBUG_printf(("cupsFileSeek(fp=%p, pos=" CUPS_LLFMT ")", (void *)fp, CUPS_LLCAST pos));
1854
1855 /*
1856 * Range check input...
1857 */
1858
1859 if (!fp || pos < 0 || fp->mode != 'r')
1860 return (-1);
1861
1862 DEBUG_printf(("2cupsFileSeek: fp->pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos));
1863 DEBUG_printf(("2cupsFileSeek: fp->ptr=%p, fp->end=%p", (void *)fp->ptr, (void *)fp->end));
1864
1865 /*
1866 * Handle special cases...
1867 */
1868
1869 if (pos == 0)
1870 return (cupsFileRewind(fp));
1871
1872 if (fp->ptr)
1873 {
1874 bytes = (ssize_t)(fp->end - fp->buf);
1875
1876 DEBUG_printf(("2cupsFileSeek: bytes=" CUPS_LLFMT, CUPS_LLCAST bytes));
1877
1878 if (pos >= fp->bufpos && pos < (fp->bufpos + bytes))
1879 {
1880 /*
1881 * No seeking necessary...
1882 */
1883
1884 fp->pos = pos;
1885 fp->ptr = fp->buf + (pos - fp->bufpos);
1886 fp->eof = 0;
1887
1888 return (pos);
1889 }
1890 }
1891
1892#ifdef HAVE_LIBZ
1893 if (!fp->compressed && !fp->ptr)
1894 {
1895 /*
1896 * Preload a buffer to determine whether the file is compressed...
1897 */
1898
1899 if (cups_fill(fp) <= 0)
1900 return (-1);
1901 }
1902#endif /* HAVE_LIBZ */
1903

Callers 9

token_cbFunction · 0.85
cat_tarFunction · 0.85
load_tarFunction · 0.85
mime_check_rulesFunction · 0.85
copy_bytesFunction · 0.85
_ppdCacheCreateWithFileFunction · 0.85
random_testsFunction · 0.85
_ippFileReadTokenFunction · 0.85

Calls 2

cupsFileRewindFunction · 0.85
cups_fillFunction · 0.85

Tested by 1

random_testsFunction · 0.68