You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 10, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Mar 10, 2026. It is now read-only.
cupsFileTell() returns invalid results for append mode (log files) #2810
cupsFileTell() returns for the current file position when appending to an existing file. It should return the current file size.
This is most noticeable with the log file rotation in the scheduler - if the scheduler is restarted (very common on Mac OS X since launchd runs cupsd on demand), we lose track of the log file size and do not rotate the old access_log or error_log files.
Activity
michaelrsweet commentedon Apr 23, 2008
CUPS.org User: mike
Fixed in Subversion repository.
michaelrsweet commentedon Apr 23, 2008
"str2810.patch":
Index: file.c
--- file.c (revision 7489)
+++ file.c (working copy)
@@ -111,7 +111,8 @@
buf[4096], /* Buffer /
*ptr, / Pointer into buffer /
*end; / End of buffer data */
off_t pos; /* File position for start of buffer */
off_t pos, /* Position in file */
#ifdef HAVE_LIBZ
z_stream stream; /* (De)compression stream */
@@ -413,13 +414,14 @@
if (!fp || fp->mode != 'w')
{
DEBUG_puts(" Attempt to flush a read-only file...");
DEBUG_puts("cupsFileFlush: Attempt to flush a read-only file...");
return (-1);
}
bytes = (ssize_t)(fp->ptr - fp->buf);
DEBUG_printf((" Flushing %ld bytes...\n", (long)bytes));
DEBUG_printf(("cupsFileFlush: Flushing " CUPS_LLFMT " bytes...\n",
if (bytes > 0)
{
@@ -453,6 +455,8 @@
*/
DEBUG_printf(("cupsFileGetChar(fp=%p)\n", fp));
if (!fp || (fp->mode != 'r' && fp->mode != 's'))
{
DEBUG_puts("cupsFileGetChar: Bad arguments!");
@@ -476,6 +480,10 @@
DEBUG_printf(("cupsFileGetChar: Returning %d...\n", *(fp->ptr) & 255));
return (*(fp->ptr)++ & 255);
}
@@ -500,6 +508,10 @@
Range check input...
*/
DEBUG_printf(("cupsFileGetConf(fp=%p, buf=%p, buflen=" CUPS_LLFMT
if (!fp || (fp->mode != 'r' && fp->mode != 's') ||
!buf || buflen < 2 || !value)
{
@@ -640,6 +652,9 @@
*/
DEBUG_printf(("cupsFileGetLine(fp=%p, buf=%p, buflen=" CUPS_LLFMT ")\n",
if (!fp || (fp->mode != 'r' && fp->mode != 's') || !buf || buflen < 3)
return (0);
@@ -654,6 +669,7 @@
break;
if (ch == '\r')
{
@@ -666,7 +682,10 @@
break;
fp->pos ++;
break;
}
@@ -682,6 +701,8 @@
*ptr = '\0';
DEBUG_printf(("cupsFileGetLine: pos=" CUPS_LLFMT "\n", CUPS_LLCAST fp->pos));
return (ptr - buf);
}
@@ -706,6 +727,9 @@
*/
if (!fp || (fp->mode != 'r' && fp->mode != 's') || !buf || buflen < 2)return (NULL);
@@ -725,6 +749,7 @@
}
if (ch == '\r')
{
@@ -737,7 +762,10 @@
break;
fp->pos ++;
break;
}
@@ -755,6 +783,8 @@
*ptr = '\0';
DEBUG_printf(("cupsFileGets: pos=" CUPS_LLFMT "\n", CUPS_LLCAST fp->pos));
return (buf);
}
@@ -811,8 +841,9 @@
existing file, "a" to append to an existing file or create a new file,
or "s" to open a socket connection.
*
*
When opening a socket connection, the filename is a string of the form
"address:port" or "hostname:port". The socket will make an IPv4 or IPv6
@@ -841,7 +872,8 @@
*/
if (!filename || !mode ||
/*
@@ -918,11 +950,12 @@
/*
'cupsFileOpenFd()' - Open a CUPS file using a file descriptor.
*
*
*
@SInCE CUPS 1.2@
*/
@@ -941,7 +974,8 @@
*/
if (fd < 0 || !mode ||
/*
@@ -959,8 +993,10 @@
switch (*mode)
{
case 'w' :fp->mode = 'w';
fp->ptr = fp->buf;
fp->end = fp->buf + sizeof(fp->buf);
@@ -1091,14 +1127,25 @@
return (-1);
if (fp->mode == 's')
fp->pos += bytes;
if ((fp->ptr + bytes) > fp->end)
if (cupsFileFlush(fp))
return (-1);
fp->pos += bytes;
if (bytes > sizeof(fp->buf))
{
#ifdef HAVE_LIBZ
@@ -1163,6 +1210,8 @@
fp->pos ++;
return (0);
}
@@ -1202,6 +1251,8 @@
return (bytes);
}
@@ -1211,6 +1262,8 @@
fp->pos += bytes;
if (bytes > sizeof(fp->buf))
{
#ifdef HAVE_LIBZ
@@ -1244,8 +1297,8 @@
ssize_t count; /* Bytes read */
DEBUG_printf(("cupsFileRead(fp=%p, buf=%p, bytes=%ld)\n", fp, buf,
DEBUG_printf(("cupsFileRead(fp=%p, buf=%p, bytes=" CUPS_LLFMT ")\n", fp, buf,
/*
@@ -1267,7 +1320,8 @@
if (fp->ptr >= fp->end)
if (cups_fill(fp) <= 0)
{
@@ -1281,7 +1335,10 @@
memcpy(buf, fp->ptr, count);
fp->ptr += count;
fp->pos += count;
DEBUG_printf(("cupsFileRead: pos=" CUPS_LLFMT "\n", CUPS_LLCAST fp->pos));
/*
*/
@@ -1295,7 +1352,7 @@
*/
return ((ssize_t)total);
}
@@ -1315,6 +1372,9 @@
*/
if (!fp || fp->mode != 'r')
return (-1);
@@ -1322,18 +1382,22 @@
*/
{
/*
*/
if (fp->ptr)
{
fp->ptr = fp->buf;
fp->eof = 0;
}
return (0);
}
@@ -1351,11 +1415,14 @@
lseek(fp->fd, 0, SEEK_SET);
return (0);
}
@@ -1373,9 +1440,10 @@
ssize_t bytes; /* Number bytes in buffer */
/*
@@ -1391,19 +1459,22 @@
if (pos == 0)
return (cupsFileRewind(fp));
{
{
+
}
}
#ifdef HAVE_LIBZ
@@ -1419,26 +1490,20 @@
#endif /* HAVE_LIBZ */
/*
*/
- bytes = 0;
fp->eof = 0;
{
/*
*/
#ifdef HAVE_LIBZ
if (fp->compressed)
@@ -1446,73 +1511,71 @@
inflateEnd(&fp->stream);
while ((bytes = cups_fill(fp)) > 0)
break;
if (bytes <= 0)
return (-1);
}
else
#endif /* HAVE_LIBZ */
{
}
}
else if (pos >= (fp->pos + bytes))
else
{
/*
Need to seek forwards...
*/
DEBUG_puts(" SEEK FORWARDS");
DEBUG_puts("cupsFileSeek: SEEK FORWARDS");
#ifdef HAVE_LIBZ
if (fp->compressed)
{
while ((bytes = cups_fill(fp)) > 0)
{
break;
}
if (bytes <= 0)
return (-1);
}
else
#endif /* HAVE_LIBZ */
{
}
}
else
{
/*
* Just reposition the current pointer, since we have the right
* range...
*/
DEBUG_puts(" SEEK INSIDE BUFFER");
DEBUG_printf(("cupsFileSeek: pos=" CUPS_LLFMT "\n", CUPS_LLCAST fp->pos));
fp->ptr = fp->buf + pos - fp->pos;
- }
return (fp->pos);
}
@@ -1628,6 +1691,9 @@
off_t /* O - File position /
cupsFileTell(cups_file_t *fp) / I - CUPS file */
{
return (fp ? fp->pos : 0);
}
@@ -1645,6 +1711,8 @@
*/
if (!fp || fp->mode == 's')
return (-1);
@@ -1675,6 +1743,9 @@
*/
if (!fp || !buf || bytes < 0 || (fp->mode != 'w' && fp->mode != 's'))return (-1);
@@ -1692,6 +1763,8 @@
return ((ssize_t)bytes);
}
@@ -1701,6 +1774,8 @@
fp->pos += (off_t)bytes;
if (bytes > sizeof(fp->buf))
{
#ifdef HAVE_LIBZ
@@ -1729,8 +1804,8 @@
const char buf, / I - Buffer /
size_t bytes) / I - Number bytes */
{
DEBUG_printf(("cups_compress(fp=%p, buf=%p, bytes=%ld)\n", fp, buf,
DEBUG_printf(("cups_compress(fp=%p, buf=%p, bytes=" CUPS_LLFMT "\n", fp, buf,
/*
@@ -1751,8 +1826,8 @@
*/
DEBUG_printf((" avail_in=%d, avail_out=%d\n", fp->stream.avail_in,
DEBUG_printf(("cups_compress: avail_in=%d, avail_out=%d\n",
if (fp->stream.avail_out < (int)(sizeof(fp->cbuf) / 8))
{
@@ -1787,19 +1862,15 @@
DEBUG_printf(("cups_fill(fp=%p)\n", fp));
DEBUG_printf((" fp->ptr=%p, fp->end=%p, fp->buf=%p, "
DEBUG_printf(("cups_fill: fp->ptr=%p, fp->end=%p, fp->buf=%p, "
/*
* Update the "pos" element as needed...
- */
if (fp->ptr && fp->end)
#ifdef HAVE_LIBZ
while (!fp->ptr || fp->compressed)
{
@@ -1827,7 +1898,7 @@
Can't read from file!
*/
return (-1);
@@ -2107,6 +2178,9 @@
ssize_t total; /* Total bytes read */
DEBUG_printf(("cups_read(fp=%p, buf=%p, bytes=" CUPS_LLFMT ")\n", fp, buf,
/*
/
@@ -2125,6 +2199,8 @@
total = read(fp->fd, buf, bytes);
#endif / WIN32 */
DEBUG_printf(("cups_read: total=" CUPS_LLFMT "\n", CUPS_LLCAST total));
if (total >= 0)
break;
@@ -2159,8 +2235,8 @@
ssize_t count; /* Count this time */
DEBUG_printf(("cups_write(fp=%p, buf=%p, bytes=%ld)\n", fp, buf,
DEBUG_printf(("cups_write(fp=%p, buf=%p, bytes=" CUPS_LLFMT ")\n", fp, buf,
/*
@@ -2181,6 +2257,8 @@
count = write(fp->fd, buf, bytes);
#endif /* WIN32 */
DEBUG_printf(("cups_write: count=" CUPS_LLFMT "\n", CUPS_LLCAST count));
if (count < 0)
{
/*
@@ -2193,8 +2271,6 @@
return (-1);
}
- DEBUG_printf((" count=%ld\n", (long)count));