[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [MiNT] fseek problem in MiNTlib
On Tue, 2008-04-01 at 15:04 +0100, Alan Hourihane wrote:
> There's problems moving the buffer pointer around when using fseek in
> MiNTlib.
>
> I've seen problems with ranlib (and ar) that causes this "fast" path to
> fail and the patch attached resorts back to the absolute method all the
> time to avoid these problems.
Oops, I missed a break for SEEK_END there.
Attached - a new patch.
Alan.
Index: stdio/fseek.c
===================================================================
RCS file: /mint/mintlib/stdio/fseek.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 fseek.c
--- stdio/fseek.c 12 Oct 2000 10:56:54 -0000 1.1.1.1
+++ stdio/fseek.c 1 Apr 2008 14:35:09 -0000
@@ -67,6 +67,9 @@
__set_errno (EINVAL);
return EOF;
+ case SEEK_SET:
+ break;
+
case SEEK_END:
/* We don't know where the end of the file is,
so seek to the position in the file the user asked
@@ -91,51 +94,9 @@
relative to the end of the file. */
o = pos;
}
-
- /* Fall through to try an absolute seek. */
-
- case SEEK_SET:
- /* Make O be relative to the buffer. */
- o -= stream->__target;
- /* Make O be relative to the current position in the buffer. */
- o -= stream->__bufp - stream->__buffer;
-
- /* Fall through to see if we can do it by
- moving the pointer around in the buffer. */
+ break;
case SEEK_CUR:
- /* If the offset is small enough, we can just
- move the pointer around in the buffer. */
-
-#if 0 /* Why did I think this would ever work??? */
- if (stream->__put_limit > stream->__buffer)
- {
- /* We are writing. */
- if (stream->__bufp + o >= stream->__buffer &&
- stream->__put_limit > stream->__bufp + o &&
- stream->__get_limit > stream->__bufp + o)
- {
- /* We have read all the data we will change soon.
- We can just move the pointer around. */
- stream->__bufp += o;
- return 0;
- }
- else
- {
- /* Flush the buffer. */
- if (__flshfp(stream, EOF) == EOF)
- return EOF;
- }
- } else
-#endif
- if (o < 0 ?
- (-o <= stream->__bufp - stream->__buffer) :
- (o <= stream->__get_limit - stream->__bufp))
- {
- stream->__bufp += o;
- return 0;
- }
-
/* Turn it into an absolute seek. */
o += stream->__bufp - stream->__buffer;
o += stream->__target;