Lines Matching refs:fp
64 static ssize_t cups_compress(cups_file_t *fp, const char *buf, size_t bytes);
66 static ssize_t cups_fill(cups_file_t *fp);
68 static ssize_t cups_read(cups_file_t *fp, char *buf, size_t bytes);
69 static ssize_t cups_write(cups_file_t *fp, const char *buf, size_t bytes);
348 cupsFileClose(cups_file_t *fp) /* I - CUPS file */ in cupsFileClose() argument
355 DEBUG_printf(("cupsFileClose(fp=%p)", (void *)fp)); in cupsFileClose()
361 if (!fp) in cupsFileClose()
368 if (fp->mode == 'w') in cupsFileClose()
369 status = cupsFileFlush(fp); in cupsFileClose()
374 if (fp->compressed && status >= 0) in cupsFileClose()
376 if (fp->mode == 'r') in cupsFileClose()
382 inflateEnd(&fp->stream); in cupsFileClose()
394 fp->stream.avail_in = 0; in cupsFileClose()
398 if (fp->stream.next_out > fp->cbuf) in cupsFileClose()
400 if (cups_write(fp, (char *)fp->cbuf, in cupsFileClose()
401 (size_t)(fp->stream.next_out - fp->cbuf)) < 0) in cupsFileClose()
404 fp->stream.next_out = fp->cbuf; in cupsFileClose()
405 fp->stream.avail_out = sizeof(fp->cbuf); in cupsFileClose()
411 done = deflate(&fp->stream, Z_FINISH) == Z_STREAM_END && in cupsFileClose()
412 fp->stream.next_out == fp->cbuf; in cupsFileClose()
419 trailer[0] = (unsigned char)fp->crc; in cupsFileClose()
420 trailer[1] = (unsigned char)(fp->crc >> 8); in cupsFileClose()
421 trailer[2] = (unsigned char)(fp->crc >> 16); in cupsFileClose()
422 trailer[3] = (unsigned char)(fp->crc >> 24); in cupsFileClose()
423 trailer[4] = (unsigned char)fp->pos; in cupsFileClose()
424 trailer[5] = (unsigned char)(fp->pos >> 8); in cupsFileClose()
425 trailer[6] = (unsigned char)(fp->pos >> 16); in cupsFileClose()
426 trailer[7] = (unsigned char)(fp->pos >> 24); in cupsFileClose()
428 if (cups_write(fp, (char *)trailer, 8) < 0) in cupsFileClose()
435 deflateEnd(&(fp->stream)); in cupsFileClose()
445 if (fp->is_stdio) in cupsFileClose()
452 fd = fp->fd; in cupsFileClose()
453 mode = fp->mode; in cupsFileClose()
455 if (fp->printf_buffer) in cupsFileClose()
456 free(fp->printf_buffer); in cupsFileClose()
458 free(fp); in cupsFileClose()
483 cupsFileCompression(cups_file_t *fp) /* I - CUPS file */ in cupsFileCompression() argument
485 return (fp ? fp->compressed : CUPS_FILE_NONE); in cupsFileCompression()
496 cupsFileEOF(cups_file_t *fp) /* I - CUPS file */ in cupsFileEOF() argument
498 return (fp ? fp->eof : 1); in cupsFileEOF()
616 cupsFileFlush(cups_file_t *fp) /* I - CUPS file */ in cupsFileFlush() argument
621 DEBUG_printf(("cupsFileFlush(fp=%p)", (void *)fp)); in cupsFileFlush()
627 if (!fp || fp->mode != 'w') in cupsFileFlush()
633 bytes = (ssize_t)(fp->ptr - fp->buf); in cupsFileFlush()
641 if (fp->compressed) in cupsFileFlush()
642 bytes = cups_compress(fp, fp->buf, (size_t)bytes); in cupsFileFlush()
645 bytes = cups_write(fp, fp->buf, (size_t)bytes); in cupsFileFlush()
650 fp->ptr = fp->buf; in cupsFileFlush()
664 cupsFileGetChar(cups_file_t *fp) /* I - CUPS file */ in cupsFileGetChar() argument
670 DEBUG_printf(("4cupsFileGetChar(fp=%p)", (void *)fp)); in cupsFileGetChar()
672 if (!fp || (fp->mode != 'r' && fp->mode != 's')) in cupsFileGetChar()
678 if (fp->eof) in cupsFileGetChar()
688 …(("5cupsFileGetChar: fp->eof=%d, fp->ptr=%p, fp->end=%p", fp->eof, (void *)fp->ptr, (void *)fp->en… in cupsFileGetChar()
690 if (fp->ptr >= fp->end) in cupsFileGetChar()
691 if (cups_fill(fp) <= 0) in cupsFileGetChar()
701 DEBUG_printf(("5cupsFileGetChar: Returning %d...", *(fp->ptr) & 255)); in cupsFileGetChar()
703 fp->pos ++; in cupsFileGetChar()
705 DEBUG_printf(("6cupsFileGetChar: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos)); in cupsFileGetChar()
707 return (*(fp->ptr)++ & 255); in cupsFileGetChar()
718 cupsFileGetConf(cups_file_t *fp, /* I - CUPS file */ in cupsFileGetConf() argument
732 …", value=%p, linenum=%p)", (void *)fp, (void *)buf, CUPS_LLCAST buflen, (void *)value, (void *)lin… in cupsFileGetConf()
734 if (!fp || (fp->mode != 'r' && fp->mode != 's') || in cupsFileGetConf()
749 while (cupsFileGets(fp, buf, buflen)) in cupsFileGetConf()
861 cupsFileGetLine(cups_file_t *fp, /* I - File to read from */ in cupsFileGetLine() argument
874 …DEBUG_printf(("2cupsFileGetLine(fp=%p, buf=%p, buflen=" CUPS_LLFMT ")", (void *)fp, (void *)buf, C… in cupsFileGetLine()
876 if (!fp || (fp->mode != 'r' && fp->mode != 's') || !buf || buflen < 3) in cupsFileGetLine()
885 if (fp->ptr >= fp->end) in cupsFileGetLine()
886 if (cups_fill(fp) <= 0) in cupsFileGetLine()
889 *ptr++ = ch = *(fp->ptr)++; in cupsFileGetLine()
890 fp->pos ++; in cupsFileGetLine()
898 if (fp->ptr >= fp->end) in cupsFileGetLine()
899 if (cups_fill(fp) <= 0) in cupsFileGetLine()
902 if (*(fp->ptr) == '\n') in cupsFileGetLine()
904 *ptr++ = *(fp->ptr)++; in cupsFileGetLine()
905 fp->pos ++; in cupsFileGetLine()
922 DEBUG_printf(("4cupsFileGetLine: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos)); in cupsFileGetLine()
935 cupsFileGets(cups_file_t *fp, /* I - CUPS file */ in cupsFileGets() argument
948 …DEBUG_printf(("2cupsFileGets(fp=%p, buf=%p, buflen=" CUPS_LLFMT ")", (void *)fp, (void *)buf, CUPS… in cupsFileGets()
950 if (!fp || (fp->mode != 'r' && fp->mode != 's') || !buf || buflen < 2) in cupsFileGets()
959 if (fp->ptr >= fp->end) in cupsFileGets()
960 if (cups_fill(fp) <= 0) in cupsFileGets()
968 ch = *(fp->ptr)++; in cupsFileGets()
969 fp->pos ++; in cupsFileGets()
977 if (fp->ptr >= fp->end) in cupsFileGets()
978 if (cups_fill(fp) <= 0) in cupsFileGets()
981 if (*(fp->ptr) == '\n') in cupsFileGets()
983 fp->ptr ++; in cupsFileGets()
984 fp->pos ++; in cupsFileGets()
1003 DEBUG_printf(("4cupsFileGets: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos)); in cupsFileGets()
1016 cupsFileLock(cups_file_t *fp, /* I - CUPS file */ in cupsFileLock() argument
1023 if (!fp || fp->mode == 's') in cupsFileLock()
1031 return (_locking(fp->fd, block ? _LK_LOCK : _LK_NBLCK, 0)); in cupsFileLock()
1033 return (lockf(fp->fd, block ? F_LOCK : F_TLOCK, 0)); in cupsFileLock()
1045 cupsFileNumber(cups_file_t *fp) /* I - CUPS file */ in cupsFileNumber() argument
1047 if (fp) in cupsFileNumber()
1048 return (fp->fd); in cupsFileNumber()
1077 cups_file_t *fp; /* New CUPS file */ in cupsFileOpen() local
1167 if ((fp = cupsFileOpenFd(fd, mode)) == NULL) in cupsFileOpen()
1179 return (fp); in cupsFileOpen()
1199 cups_file_t *fp; /* New CUPS file */ in cupsFileOpenFd() local
1217 if ((fp = calloc(1, sizeof(cups_file_t))) == NULL) in cupsFileOpenFd()
1224 fp->fd = fd; in cupsFileOpenFd()
1229 fp->pos = lseek(fd, 0, SEEK_END); in cupsFileOpenFd()
1232 fp->mode = 'w'; in cupsFileOpenFd()
1233 fp->ptr = fp->buf; in cupsFileOpenFd()
1234 fp->end = fp->buf + sizeof(fp->buf); in cupsFileOpenFd()
1260 cups_write(fp, (char *)header, 10); in cupsFileOpenFd()
1266 deflateInit2(&(fp->stream), mode[1] - '0', Z_DEFLATED, -15, 8, in cupsFileOpenFd()
1269 fp->stream.next_out = fp->cbuf; in cupsFileOpenFd()
1270 fp->stream.avail_out = sizeof(fp->cbuf); in cupsFileOpenFd()
1271 fp->compressed = 1; in cupsFileOpenFd()
1272 fp->crc = crc32(0L, Z_NULL, 0); in cupsFileOpenFd()
1278 fp->mode = 'r'; in cupsFileOpenFd()
1282 fp->mode = 's'; in cupsFileOpenFd()
1294 fcntl(fp->fd, F_SETFD, fcntl(fp->fd, F_GETFD) | FD_CLOEXEC); in cupsFileOpenFd()
1297 return (fp); in cupsFileOpenFd()
1306 _cupsFilePeekAhead(cups_file_t *fp, /* I - CUPS file */ in _cupsFilePeekAhead() argument
1309 return (fp && fp->ptr && memchr(fp->ptr, ch, (size_t)(fp->end - fp->ptr))); in _cupsFilePeekAhead()
1320 cupsFilePeekChar(cups_file_t *fp) /* I - CUPS file */ in cupsFilePeekChar() argument
1326 if (!fp || (fp->mode != 'r' && fp->mode != 's')) in cupsFilePeekChar()
1333 if (fp->ptr >= fp->end) in cupsFilePeekChar()
1334 if (cups_fill(fp) <= 0) in cupsFilePeekChar()
1341 return (*(fp->ptr) & 255); in cupsFilePeekChar()
1352 cupsFilePrintf(cups_file_t *fp, /* I - CUPS file */ in cupsFilePrintf() argument
1360 DEBUG_printf(("2cupsFilePrintf(fp=%p, format=\"%s\", ...)", (void *)fp, format)); in cupsFilePrintf()
1362 if (!fp || !format || (fp->mode != 'w' && fp->mode != 's')) in cupsFilePrintf()
1365 if (!fp->printf_buffer) in cupsFilePrintf()
1371 if ((fp->printf_buffer = malloc(1024)) == NULL) in cupsFilePrintf()
1374 fp->printf_size = 1024; in cupsFilePrintf()
1378 bytes = vsnprintf(fp->printf_buffer, fp->printf_size, format, ap); in cupsFilePrintf()
1381 if (bytes >= (ssize_t)fp->printf_size) in cupsFilePrintf()
1393 if ((temp = realloc(fp->printf_buffer, (size_t)(bytes + 1))) == NULL) in cupsFilePrintf()
1396 fp->printf_buffer = temp; in cupsFilePrintf()
1397 fp->printf_size = (size_t)(bytes + 1); in cupsFilePrintf()
1400 bytes = vsnprintf(fp->printf_buffer, fp->printf_size, format, ap); in cupsFilePrintf()
1404 if (fp->mode == 's') in cupsFilePrintf()
1406 if (cups_write(fp, fp->printf_buffer, (size_t)bytes) < 0) in cupsFilePrintf()
1409 fp->pos += bytes; in cupsFilePrintf()
1411 DEBUG_printf(("4cupsFilePrintf: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos)); in cupsFilePrintf()
1416 if ((fp->ptr + bytes) > fp->end) in cupsFilePrintf()
1417 if (cupsFileFlush(fp)) in cupsFilePrintf()
1420 fp->pos += bytes; in cupsFilePrintf()
1422 DEBUG_printf(("4cupsFilePrintf: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos)); in cupsFilePrintf()
1424 if ((size_t)bytes > sizeof(fp->buf)) in cupsFilePrintf()
1427 if (fp->compressed) in cupsFilePrintf()
1428 return ((int)cups_compress(fp, fp->printf_buffer, (size_t)bytes)); in cupsFilePrintf()
1431 return ((int)cups_write(fp, fp->printf_buffer, (size_t)bytes)); in cupsFilePrintf()
1435 memcpy(fp->ptr, fp->printf_buffer, (size_t)bytes); in cupsFilePrintf()
1436 fp->ptr += bytes; in cupsFilePrintf()
1438 if (fp->is_stdio && cupsFileFlush(fp)) in cupsFilePrintf()
1453 cupsFilePutChar(cups_file_t *fp, /* I - CUPS file */ in cupsFilePutChar() argument
1460 if (!fp || (fp->mode != 'w' && fp->mode != 's')) in cupsFilePutChar()
1463 if (fp->mode == 's') in cupsFilePutChar()
1474 if (send(fp->fd, &ch, 1, 0) < 1) in cupsFilePutChar()
1483 if (fp->ptr >= fp->end) in cupsFilePutChar()
1484 if (cupsFileFlush(fp)) in cupsFilePutChar()
1487 *(fp->ptr) ++ = (char)c; in cupsFilePutChar()
1490 fp->pos ++; in cupsFilePutChar()
1492 DEBUG_printf(("4cupsFilePutChar: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos)); in cupsFilePutChar()
1507 cupsFilePutConf(cups_file_t *fp, /* I - CUPS file */ in cupsFilePutConf() argument
1516 if (!fp || !directive || !*directive) in cupsFilePutConf()
1519 if ((bytes = cupsFilePuts(fp, directive)) < 0) in cupsFilePutConf()
1522 if (cupsFilePutChar(fp, ' ') < 0) in cupsFilePutConf()
1534 if ((temp = cupsFileWrite(fp, value, (size_t)(ptr - value))) < 0) in cupsFilePutConf()
1538 if (cupsFilePutChar(fp, '\\') < 0) in cupsFilePutConf()
1542 if ((temp = cupsFilePuts(fp, ptr)) < 0) in cupsFilePutConf()
1546 else if ((temp = cupsFilePuts(fp, value)) < 0) in cupsFilePutConf()
1552 if (cupsFilePutChar(fp, '\n') < 0) in cupsFilePutConf()
1568 cupsFilePuts(cups_file_t *fp, /* I - CUPS file */ in cupsFilePuts() argument
1578 if (!fp || !s || (fp->mode != 'w' && fp->mode != 's')) in cupsFilePuts()
1587 if (fp->mode == 's') in cupsFilePuts()
1589 if (cups_write(fp, s, (size_t)bytes) < 0) in cupsFilePuts()
1592 fp->pos += bytes; in cupsFilePuts()
1594 DEBUG_printf(("4cupsFilePuts: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos)); in cupsFilePuts()
1599 if ((fp->ptr + bytes) > fp->end) in cupsFilePuts()
1600 if (cupsFileFlush(fp)) in cupsFilePuts()
1603 fp->pos += bytes; in cupsFilePuts()
1605 DEBUG_printf(("4cupsFilePuts: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos)); in cupsFilePuts()
1607 if ((size_t)bytes > sizeof(fp->buf)) in cupsFilePuts()
1610 if (fp->compressed) in cupsFilePuts()
1611 return ((int)cups_compress(fp, s, (size_t)bytes)); in cupsFilePuts()
1614 return ((int)cups_write(fp, s, (size_t)bytes)); in cupsFilePuts()
1618 memcpy(fp->ptr, s, (size_t)bytes); in cupsFilePuts()
1619 fp->ptr += bytes; in cupsFilePuts()
1621 if (fp->is_stdio && cupsFileFlush(fp)) in cupsFilePuts()
1636 cupsFileRead(cups_file_t *fp, /* I - CUPS file */ in cupsFileRead() argument
1644 …DEBUG_printf(("2cupsFileRead(fp=%p, buf=%p, bytes=" CUPS_LLFMT ")", (void *)fp, (void *)buf, CUPS_… in cupsFileRead()
1650 if (!fp || !buf || (fp->mode != 'r' && fp->mode != 's')) in cupsFileRead()
1656 if (fp->eof) in cupsFileRead()
1669 if (fp->ptr >= fp->end) in cupsFileRead()
1670 if (cups_fill(fp) <= 0) in cupsFileRead()
1681 count = (ssize_t)(fp->end - fp->ptr); in cupsFileRead()
1685 memcpy(buf, fp->ptr,(size_t) count); in cupsFileRead()
1686 fp->ptr += count; in cupsFileRead()
1687 fp->pos += count; in cupsFileRead()
1689 DEBUG_printf(("4cupsFileRead: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos)); in cupsFileRead()
1718 cupsFileRewind(cups_file_t *fp) /* I - CUPS file */ in cupsFileRewind() argument
1724 DEBUG_printf(("cupsFileRewind(fp=%p)", (void *)fp)); in cupsFileRewind()
1725 DEBUG_printf(("2cupsFileRewind: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos)); in cupsFileRewind()
1727 if (!fp || fp->mode != 'r') in cupsFileRewind()
1734 if (fp->bufpos == 0) in cupsFileRewind()
1740 fp->pos = 0; in cupsFileRewind()
1742 if (fp->ptr) in cupsFileRewind()
1744 fp->ptr = fp->buf; in cupsFileRewind()
1745 fp->eof = 0; in cupsFileRewind()
1748 DEBUG_printf(("2cupsFileRewind: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos)); in cupsFileRewind()
1758 if (fp->compressed) in cupsFileRewind()
1760 inflateEnd(&fp->stream); in cupsFileRewind()
1761 fp->compressed = 0; in cupsFileRewind()
1765 if (lseek(fp->fd, 0, SEEK_SET)) in cupsFileRewind()
1771 fp->bufpos = 0; in cupsFileRewind()
1772 fp->pos = 0; in cupsFileRewind()
1773 fp->ptr = NULL; in cupsFileRewind()
1774 fp->end = NULL; in cupsFileRewind()
1775 fp->eof = 0; in cupsFileRewind()
1777 DEBUG_printf(("2cupsFileRewind: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos)); in cupsFileRewind()
1790 cupsFileSeek(cups_file_t *fp, /* I - CUPS file */ in cupsFileSeek() argument
1796 DEBUG_printf(("cupsFileSeek(fp=%p, pos=" CUPS_LLFMT ")", (void *)fp, CUPS_LLCAST pos)); in cupsFileSeek()
1797 DEBUG_printf(("2cupsFileSeek: fp->pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos)); in cupsFileSeek()
1798 DEBUG_printf(("2cupsFileSeek: fp->ptr=%p, fp->end=%p", (void *)fp->ptr, (void *)fp->end)); in cupsFileSeek()
1804 if (!fp || pos < 0 || fp->mode != 'r') in cupsFileSeek()
1812 return (cupsFileRewind(fp)); in cupsFileSeek()
1814 if (fp->ptr) in cupsFileSeek()
1816 bytes = (ssize_t)(fp->end - fp->buf); in cupsFileSeek()
1820 if (pos >= fp->bufpos && pos < (fp->bufpos + bytes)) in cupsFileSeek()
1826 fp->pos = pos; in cupsFileSeek()
1827 fp->ptr = fp->buf + pos - fp->bufpos; in cupsFileSeek()
1828 fp->eof = 0; in cupsFileSeek()
1835 if (!fp->compressed && !fp->ptr) in cupsFileSeek()
1841 if (cups_fill(fp) <= 0) in cupsFileSeek()
1850 fp->eof = 0; in cupsFileSeek()
1852 if (pos < fp->bufpos) in cupsFileSeek()
1861 if (fp->compressed) in cupsFileSeek()
1863 inflateEnd(&fp->stream); in cupsFileSeek()
1865 lseek(fp->fd, 0, SEEK_SET); in cupsFileSeek()
1866 fp->bufpos = 0; in cupsFileSeek()
1867 fp->pos = 0; in cupsFileSeek()
1868 fp->ptr = NULL; in cupsFileSeek()
1869 fp->end = NULL; in cupsFileSeek()
1871 while ((bytes = cups_fill(fp)) > 0) in cupsFileSeek()
1872 if (pos >= fp->bufpos && pos < (fp->bufpos + bytes)) in cupsFileSeek()
1878 fp->ptr = fp->buf + pos - fp->bufpos; in cupsFileSeek()
1879 fp->pos = pos; in cupsFileSeek()
1884 fp->bufpos = lseek(fp->fd, pos, SEEK_SET); in cupsFileSeek()
1885 fp->pos = fp->bufpos; in cupsFileSeek()
1886 fp->ptr = NULL; in cupsFileSeek()
1887 fp->end = NULL; in cupsFileSeek()
1890 CUPS_LLCAST fp->pos)); in cupsFileSeek()
1902 if (fp->compressed) in cupsFileSeek()
1904 while ((bytes = cups_fill(fp)) > 0) in cupsFileSeek()
1906 if (pos >= fp->bufpos && pos < (fp->bufpos + bytes)) in cupsFileSeek()
1913 fp->ptr = fp->buf + pos - fp->bufpos; in cupsFileSeek()
1914 fp->pos = pos; in cupsFileSeek()
1919 fp->bufpos = lseek(fp->fd, pos, SEEK_SET); in cupsFileSeek()
1920 fp->pos = fp->bufpos; in cupsFileSeek()
1921 fp->ptr = NULL; in cupsFileSeek()
1922 fp->end = NULL; in cupsFileSeek()
1925 CUPS_LLCAST fp->pos)); in cupsFileSeek()
1929 DEBUG_printf(("2cupsFileSeek: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos)); in cupsFileSeek()
1931 return (fp->pos); in cupsFileSeek()
2044 cupsFileTell(cups_file_t *fp) /* I - CUPS file */ in cupsFileTell() argument
2046 DEBUG_printf(("2cupsFileTell(fp=%p)", (void *)fp)); in cupsFileTell()
2047 DEBUG_printf(("3cupsFileTell: pos=" CUPS_LLFMT, CUPS_LLCAST (fp ? fp->pos : -1))); in cupsFileTell()
2049 return (fp ? fp->pos : 0); in cupsFileTell()
2060 cupsFileUnlock(cups_file_t *fp) /* I - CUPS file */ in cupsFileUnlock() argument
2066 DEBUG_printf(("cupsFileUnlock(fp=%p)", (void *)fp)); in cupsFileUnlock()
2068 if (!fp || fp->mode == 's') in cupsFileUnlock()
2076 return (_locking(fp->fd, _LK_UNLCK, 0)); in cupsFileUnlock()
2078 return (lockf(fp->fd, F_ULOCK, 0)); in cupsFileUnlock()
2090 cupsFileWrite(cups_file_t *fp, /* I - CUPS file */ in cupsFileWrite() argument
2098 …DEBUG_printf(("2cupsFileWrite(fp=%p, buf=%p, bytes=" CUPS_LLFMT ")", (void *)fp, (void *)buf, CUPS… in cupsFileWrite()
2100 if (!fp || !buf || (fp->mode != 'w' && fp->mode != 's')) in cupsFileWrite()
2110 if (fp->mode == 's') in cupsFileWrite()
2112 if (cups_write(fp, buf, bytes) < 0) in cupsFileWrite()
2115 fp->pos += (off_t)bytes; in cupsFileWrite()
2117 DEBUG_printf(("4cupsFileWrite: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos)); in cupsFileWrite()
2122 if ((fp->ptr + bytes) > fp->end) in cupsFileWrite()
2123 if (cupsFileFlush(fp)) in cupsFileWrite()
2126 fp->pos += (off_t)bytes; in cupsFileWrite()
2128 DEBUG_printf(("4cupsFileWrite: pos=" CUPS_LLFMT, CUPS_LLCAST fp->pos)); in cupsFileWrite()
2130 if (bytes > sizeof(fp->buf)) in cupsFileWrite()
2133 if (fp->compressed) in cupsFileWrite()
2134 return (cups_compress(fp, buf, bytes)); in cupsFileWrite()
2137 return (cups_write(fp, buf, bytes)); in cupsFileWrite()
2141 memcpy(fp->ptr, buf, bytes); in cupsFileWrite()
2142 fp->ptr += bytes; in cupsFileWrite()
2154 cups_compress(cups_file_t *fp, /* I - CUPS file */ in cups_compress() argument
2158 …DEBUG_printf(("7cups_compress(fp=%p, buf=%p, bytes=" CUPS_LLFMT ")", (void *)fp, (void *)buf, CUPS… in cups_compress()
2164 fp->crc = crc32(fp->crc, (const Bytef *)buf, (uInt)bytes); in cups_compress()
2170 fp->stream.next_in = (Bytef *)buf; in cups_compress()
2171 fp->stream.avail_in = (uInt)bytes; in cups_compress()
2173 while (fp->stream.avail_in > 0) in cups_compress()
2180 fp->stream.avail_in, fp->stream.avail_out)); in cups_compress()
2182 if (fp->stream.avail_out < (uInt)(sizeof(fp->cbuf) / 8)) in cups_compress()
2184 if (cups_write(fp, (char *)fp->cbuf, (size_t)(fp->stream.next_out - fp->cbuf)) < 0) in cups_compress()
2187 fp->stream.next_out = fp->cbuf; in cups_compress()
2188 fp->stream.avail_out = sizeof(fp->cbuf); in cups_compress()
2191 deflate(&(fp->stream), Z_NO_FLUSH); in cups_compress()
2204 cups_fill(cups_file_t *fp) /* I - CUPS file */ in cups_fill() argument
2214 DEBUG_printf(("7cups_fill(fp=%p)", (void *)fp)); in cups_fill()
2215 …fpos=" CUPS_LLFMT ", fp->eof=%d", (void *)fp->ptr, (void *)fp->end, (void *)fp->buf, CUPS_LLCAST f… in cups_fill()
2217 if (fp->ptr && fp->end) in cups_fill()
2218 fp->bufpos += fp->end - fp->buf; in cups_fill()
2221 DEBUG_printf(("9cups_fill: fp->compressed=%d", fp->compressed)); in cups_fill()
2223 while (!fp->ptr || fp->compressed) in cups_fill()
2230 if (!fp->ptr) in cups_fill()
2236 fp->compressed = 0; in cups_fill()
2243 if ((bytes = cups_read(fp, (char *)fp->buf, sizeof(fp->buf))) < 0) in cups_fill()
2252 fp->eof = 1; in cups_fill()
2257 if (bytes < 10 || fp->buf[0] != 0x1f || in cups_fill()
2258 (fp->buf[1] & 255) != 0x8b || in cups_fill()
2259 fp->buf[2] != 8 || (fp->buf[3] & 0xe0) != 0) in cups_fill()
2265 fp->ptr = fp->buf; in cups_fill()
2266 fp->end = fp->buf + bytes; in cups_fill()
2278 ptr = (unsigned char *)fp->buf + 10; in cups_fill()
2279 end = (unsigned char *)fp->buf + bytes; in cups_fill()
2281 if (fp->buf[3] & 0x04) in cups_fill()
2295 fp->eof = 1; in cups_fill()
2312 fp->eof = 1; in cups_fill()
2319 if (fp->buf[3] & 0x08) in cups_fill()
2338 fp->eof = 1; in cups_fill()
2345 if (fp->buf[3] & 0x10) in cups_fill()
2364 fp->eof = 1; in cups_fill()
2371 if (fp->buf[3] & 0x02) in cups_fill()
2387 fp->eof = 1; in cups_fill()
2399 memcpy(fp->cbuf, ptr, (size_t)bytes); in cups_fill()
2405 fp->stream.zalloc = (alloc_func)0; in cups_fill()
2406 fp->stream.zfree = (free_func)0; in cups_fill()
2407 fp->stream.opaque = (voidpf)0; in cups_fill()
2408 fp->stream.next_in = (Bytef *)fp->cbuf; in cups_fill()
2409 fp->stream.next_out = NULL; in cups_fill()
2410 fp->stream.avail_in = (uInt)bytes; in cups_fill()
2411 fp->stream.avail_out = 0; in cups_fill()
2412 fp->crc = crc32(0L, Z_NULL, 0); in cups_fill()
2414 if ((status = inflateInit2(&(fp->stream), -15)) != Z_OK) in cups_fill()
2418 fp->eof = 1; in cups_fill()
2424 fp->compressed = 1; in cups_fill()
2427 if (fp->compressed) in cups_fill()
2433 if (fp->eof) in cups_fill()
2444 if (fp->stream.avail_in == 0) in cups_fill()
2446 if ((bytes = cups_read(fp, (char *)fp->cbuf, sizeof(fp->cbuf))) <= 0) in cups_fill()
2450 fp->eof = 1; in cups_fill()
2455 fp->stream.next_in = fp->cbuf; in cups_fill()
2456 fp->stream.avail_in = (uInt)bytes; in cups_fill()
2463 fp->stream.next_out = (Bytef *)fp->buf; in cups_fill()
2464 fp->stream.avail_out = sizeof(fp->buf); in cups_fill()
2466 status = inflate(&(fp->stream), Z_NO_FLUSH); in cups_fill()
2468 if (fp->stream.next_out > (Bytef *)fp->buf) in cups_fill()
2469 fp->crc = crc32(fp->crc, (Bytef *)fp->buf, in cups_fill()
2470 (uInt)(fp->stream.next_out - (Bytef *)fp->buf)); in cups_fill()
2482 if (fp->stream.avail_in > 0) in cups_fill()
2484 if (fp->stream.avail_in > sizeof(trailer)) in cups_fill()
2487 tbytes = (ssize_t)fp->stream.avail_in; in cups_fill()
2489 memcpy(trailer, fp->stream.next_in, (size_t)tbytes); in cups_fill()
2490 fp->stream.next_in += tbytes; in cups_fill()
2491 fp->stream.avail_in -= (size_t)tbytes; in cups_fill()
2496 …if (read(fp->fd, trailer + tbytes, sizeof(trailer) - (size_t)tbytes) < ((ssize_t)sizeof(trailer) -… in cups_fill()
2504 fp->eof = 1; in cups_fill()
2514 if (tcrc != fp->crc) in cups_fill()
2520 …9cups_fill: tcrc=%08x != fp->crc=%08x, returning -1.", (unsigned int)tcrc, (unsigned int)fp->crc)); in cups_fill()
2522 fp->eof = 1; in cups_fill()
2533 inflateEnd(&fp->stream); in cups_fill()
2535 fp->compressed = 0; in cups_fill()
2541 fp->eof = 1; in cups_fill()
2547 bytes = (ssize_t)sizeof(fp->buf) - (ssize_t)fp->stream.avail_out; in cups_fill()
2553 fp->ptr = fp->buf; in cups_fill()
2554 fp->end = fp->buf + bytes; in cups_fill()
2569 if ((bytes = cups_read(fp, fp->buf, sizeof(fp->buf))) <= 0) in cups_fill()
2575 fp->eof = 1; in cups_fill()
2576 fp->ptr = fp->buf; in cups_fill()
2577 fp->end = fp->buf; in cups_fill()
2585 fp->eof = 0; in cups_fill()
2586 fp->ptr = fp->buf; in cups_fill()
2587 fp->end = fp->buf + bytes; in cups_fill()
2689 cups_read(cups_file_t *fp, /* I - CUPS file */ in cups_read() argument
2696 …DEBUG_printf(("7cups_read(fp=%p, buf=%p, bytes=" CUPS_LLFMT ")", (void *)fp, (void *)buf, CUPS_LLC… in cups_read()
2705 if (fp->mode == 's') in cups_read()
2706 total = (ssize_t)recv(fp->fd, buf, (unsigned)bytes, 0); in cups_read()
2708 total = (ssize_t)read(fp->fd, buf, (unsigned)bytes); in cups_read()
2710 if (fp->mode == 's') in cups_read()
2711 total = recv(fp->fd, buf, bytes, 0); in cups_read()
2713 total = read(fp->fd, buf, bytes); in cups_read()
2744 cups_write(cups_file_t *fp, /* I - CUPS file */ in cups_write() argument
2752 …DEBUG_printf(("7cups_write(fp=%p, buf=%p, bytes=" CUPS_LLFMT ")", (void *)fp, (void *)buf, CUPS_LL… in cups_write()
2762 if (fp->mode == 's') in cups_write()
2763 count = (ssize_t)send(fp->fd, buf, (unsigned)bytes, 0); in cups_write()
2765 count = (ssize_t)write(fp->fd, buf, (unsigned)bytes); in cups_write()
2767 if (fp->mode == 's') in cups_write()
2768 count = send(fp->fd, buf, bytes, 0); in cups_write()
2770 count = write(fp->fd, buf, bytes); in cups_write()