Wed Dec 20 18:23:10 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>

* stdio/internals.c (flushbuf): If the target is -1, always
	discard the buffer of read data.
	Only set TWIDDLED flag in !ALIGNED case.
	Never increment target or offset when old value is -1.
This commit is contained in:
Roland McGrath 1995-12-21 10:00:22 +00:00
parent f94a3574d5
commit 8ef76445e8
2 changed files with 31 additions and 16 deletions

View File

@ -1,3 +1,10 @@
Wed Dec 20 18:23:10 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
* stdio/internals.c (flushbuf): If the target is -1, always
discard the buffer of read data.
Only set TWIDDLED flag in !ALIGNED case.
Never increment target or offset when old value is -1.
Tue Dec 19 17:00:42 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu> Tue Dec 19 17:00:42 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
* hurd/hurdpid.c (_S_msg_proc_newids): Only run the hook when the * hurd/hurdpid.c (_S_msg_proc_newids): Only run the hook when the

View File

@ -199,6 +199,11 @@ DEFUN(flushbuf, (fp, c),
size_t buffer_offset = 0; size_t buffer_offset = 0;
if (fp->__target == -1)
/* For an unseekable object, data recently read bears no relation
to data we will write later. Discard the buffer. */
fp->__get_limit = fp->__buffer;
else
/* If the user has read some of the buffer, the target position /* If the user has read some of the buffer, the target position
is incremented for each character he has read. */ is incremented for each character he has read. */
fp->__target += fp->__bufp - fp->__buffer; fp->__target += fp->__bufp - fp->__buffer;
@ -231,13 +236,13 @@ DEFUN(flushbuf, (fp, c),
/* Start bufp as far into the buffer as we were into /* Start bufp as far into the buffer as we were into
this block before we read it. */ this block before we read it. */
buffer_offset = o; buffer_offset = o;
}
/* The target position is now set to where the beginning of the /* The target position is now set to where the beginning of the
buffer maps to; and the get_limit was set by the input-room buffer maps to; and the get_limit was set by the input-room
function. */ function. */
twiddled = 1; twiddled = 1;
} }
}
if (fp->__buffer != NULL) if (fp->__buffer != NULL)
{ {
@ -289,6 +294,7 @@ DEFUN(flushbuf, (fp, c),
call with nothing in the buffer, so just say the buffer's call with nothing in the buffer, so just say the buffer's
been flushed, increment the file offset, and return. */ been flushed, increment the file offset, and return. */
fp->__bufp = fp->__buffer; fp->__bufp = fp->__buffer;
if (fp->__offset != -1)
fp->__offset += to_write; fp->__offset += to_write;
goto end; goto end;
} }
@ -315,7 +321,7 @@ DEFUN(flushbuf, (fp, c),
bother to find the current position; we can get it bother to find the current position; we can get it
later if we need it. */ later if we need it. */
fp->__offset = fp->__target = -1; fp->__offset = fp->__target = -1;
else else if (fp->__offset != -1)
/* Record that we've moved forward in the file. */ /* Record that we've moved forward in the file. */
fp->__offset += wrote; fp->__offset += wrote;
} }
@ -339,7 +345,7 @@ DEFUN(flushbuf, (fp, c),
char cc = (unsigned char) c; char cc = (unsigned char) c;
if ((*fp->__io_funcs.__write)(fp->__cookie, &cc, 1) < 1) if ((*fp->__io_funcs.__write)(fp->__cookie, &cc, 1) < 1)
fp->__error = 1; fp->__error = 1;
else else if (fp->__offset != -1)
{ {
/* Record that we've moved forward in the file. */ /* Record that we've moved forward in the file. */
++fp->__offset; ++fp->__offset;
@ -355,6 +361,7 @@ DEFUN(flushbuf, (fp, c),
if (!twiddled) if (!twiddled)
{ {
if (fp->__target != -1)
/* The new target position moves up as /* The new target position moves up as
much as the user wrote into the buffer. */ much as the user wrote into the buffer. */
fp->__target += buffer_written; fp->__target += buffer_written;
@ -433,6 +440,7 @@ DEFUN(fillbuf, (fp), register FILE *fp)
buffer += count; buffer += count;
nread += count; nread += count;
to_read -= count; to_read -= count;
if (fp->__offset != -1)
/* Record that we've moved forward in the file. */ /* Record that we've moved forward in the file. */
fp->__offset += count; fp->__offset += count;
} }