Index: testfile.c =================================================================== --- testfile.c (revision 6961) +++ testfile.c (working copy) @@ -16,7 +16,8 @@ * * Contents: * - * main() - Main entry. + * main() - Main entry. + * read_write_tests() - Perform read/write tests. */ /* @@ -149,6 +150,8 @@ unsigned char readbuf[8192], /* Read buffer */ writebuf[8192]; /* Write buffer */ int byte; /* Byte from file */ + static const char *partial_line = "partial line"; + /* Partial line */ /* @@ -253,11 +256,11 @@ fputs("cupsFileWrite(): ", stdout); - for (i = 0; i < 100; i ++) + for (i = 0; i < 10000; i ++) if (cupsFileWrite(fp, (char *)writebuf, sizeof(writebuf)) < 0) break; - if (i >= 100) + if (i >= 10000) puts("PASS"); else { @@ -266,6 +269,20 @@ } /* + * cupsFilePuts() with partial line... + */ + + fputs("cupsFilePuts(\"partial line\"): ", stdout); + + if (cupsFilePuts(fp, partial_line) > 0) + puts("PASS"); + else + { + printf("FAIL (%s)\n", strerror(errno)); + status ++; + } + + /* * cupsFileClose() */ @@ -405,13 +422,13 @@ fputs("cupsFileRead(): ", stdout); - for (i = 0; i < 100; i ++) + for (i = 0; i < 10000; i ++) if ((byte = cupsFileRead(fp, (char *)readbuf, sizeof(readbuf))) < 0) break; else if (memcmp(readbuf, writebuf, sizeof(readbuf))) break; - if (i >= 100) + if (i >= 10000) puts("PASS"); else if (byte > 0) { @@ -431,6 +448,26 @@ } /* + * cupsFileGetChar() with partial line... + */ + + fputs("cupsFileGetChar(partial line): ", stdout); + + for (i = 0; i < strlen(partial_line); i ++) + if ((byte = cupsFileGetChar(fp)) < 0) + break; + else if (byte != partial_line[i]) + break; + + if (!partial_line[i]) + puts("PASS"); + else + { + printf("FAIL (got '%c', expected '%c')\n", byte, partial_line[i]); + status ++; + } + + /* * cupsFileClose() */ Index: file.c =================================================================== --- file.c (revision 6961) +++ file.c (working copy) @@ -1207,7 +1207,7 @@ if (fp->ptr >= fp->end) if (cups_fill(fp) <= 0) { - DEBUG_printf((" cups_fill() returned -1, total=%d\n", total)); + DEBUG_printf((" cups_fill() returned -1, total=%d\n", (int)total)); if (total > 0) return ((ssize_t)total); @@ -1235,7 +1235,7 @@ * Return the total number of bytes read... */ - DEBUG_printf((" total=%d\n", total)); + DEBUG_printf((" total=%d\n", (int)total)); return ((ssize_t)total); } @@ -1703,6 +1703,7 @@ { ssize_t bytes; /* Number of bytes read */ #ifdef HAVE_LIBZ + int status; /* Decompression status */ const unsigned char *ptr, /* Pointer into buffer */ *end; /* End of buffer */ #endif /* HAVE_LIBZ */ @@ -1921,7 +1922,13 @@ fp->stream.next_out = (Bytef *)fp->buf; fp->stream.avail_out = sizeof(fp->buf); - if (inflate(&(fp->stream), Z_NO_FLUSH) == Z_STREAM_END) + status = inflate(&(fp->stream), Z_NO_FLUSH); + + if (fp->stream.next_out > (Bytef *)fp->buf) + fp->crc = crc32(fp->crc, (Bytef *)fp->buf, + fp->stream.next_out - (Bytef *)fp->buf); + + if (status == Z_STREAM_END) { /* * Read the CRC and length... @@ -1950,6 +1957,9 @@ * Bad CRC, mark end-of-file... */ + DEBUG_printf(("cups_fill: tcrc=%08x, fp->crc=%08x\n", + (unsigned int)tcrc, (unsigned int)fp->crc)); + fp->eof = 1; return (-1);