Subject: RE: Cygwin B20 - fseek under gcc fails to reposition on text files
From: Earnie Boyd <[email-masked]>
To: Peter Kabal <[email-masked]>
Cc: cygwin users <[email-masked]>
Date: Tue, 16 Feb 1999 07:41:34 -0800 (PST)

Ok I appoligize.

Here is the "Microsoft VC++ Run-Time Library Reference" quote:

For streams opened in text mode, fseek has limited use, because
carriage return-linefeed translations can cause fseek to produce
unexpected results.  The only fseek operations guaranteed to work on
streams opened in text mode are:

* Seeking with an offset of 0 relative to any of the origin values.

* Seeking from the beginning of the file with an offset value returned
from a call to ftell.

Also in text mode, CTRL+Z is interpreted as an end-of-file character
on input.  In files opened for reading/writing, fopen and all related
routines check for a CTRL+Z at the end of the file and remove it if
possible.  This is done because using fseek and ftell to move within
an file that ends in CTRL+Z may cause fseek to behave improperly near
the end of the file.

---

Based on the documentation then I'll have to agree that your programs
isn't behaving as the documentation states that it should.  But, which
is wrong, fseek or ftell?

Sorry for speaking out of line,
Earnie.

---Peter Kabal <[email-masked]> wrote:
>
> I did.  I quote from Harbison and Steele, Fourth edition, p 353.
> 
> "The following, more limited set of calls is permitted on text streams
> by ISO C:
> 
> fseek (stream, 0L, SEEK_SET)
> fseek (stream, 0L, SEEK_CUR)
> fseek (stream, 0L, SEEK_END)
> fseek (stream, 0L, ftell_pos, SEEK_SET)  at a position returned by a
>     previous call to ftell for stream.
> "
> 
> I <did> read the docs about "text mode processing"!  Your comment was
> unwarranted and warrants an apology.
> 
> > -----Original Message-----
> > From: Earnie Boyd [mailto:[email-masked]]
> > Sent: February 16, 1999 8:28 AM
> > To: [email-masked]
> > Cc: cygwin users
> > Subject: Re: Cygwin B20 - fseek under gcc fails to reposition on
text
> > files
> > 
> > 
> > 
> > You need to read the docs about "text mode processing".  This is
> > exactly the expected behavior.  If you're going to use these
functions
> > then you must process in binary mode.
> > 
> > Regards,
> > Earnie.
> > 
> > ---Peter Kabal <[email-masked]> wrote:
> > >
> > > Consider a text file (CR/LF line endings).  Read a line, save the
> > > current position, seek to end-of-file, seek to the saved position,
> > > read a line.  The second read does not return the second line of
> > > the file.
> > > 
> > > A shell script which tests the problem is included below:
> > >
---------------------------------------------------------------------
> > > #!/bin/sh
> > > #
> > > # Test fseek bug
> > > # On Cygwin 20.1, a file is not correctly repositioned after
seeking
> > to the
> > > # end-of-file on a text file (CR/LF line endings).
> > > 
> > > cat > tfrepos.c << EoF
> > > #include <stdio.h>
> > > int main (int argc, char *argv[])
> > > {
> > >   FILE *fp;
> > >   long int pos, size;
> > >   char line[200];
> > >   char *p;
> > > 
> > >   fp = fopen (argv[1], "r");
> > >   p = fgets (line, 200, fp);
> > >   printf (" Line: %s", p);
> > > 
> > >   pos = ftell (fp);
> > >   fseek (fp, 0L, SEEK_END);
> > >   fseek (fp, pos, SEEK_SET);
> > > 
> > >   p = fgets (line, 200, fp);
> > >   printf (" Line: %s", p);
> > > 
> > >   return 0;
> > > }
> > > EoF
> > > 
> > > # Run the test program with the c-program as input
> > > gcc tfrepos.c -o tfrepos
> > > ./tfrepos tfrepos.c
> > > 
> > > # Clean up
> > > rm -f tfrepos tfrepos.c
> > >
---------------------------------------------------------------------
> > > 
> > > Peter Kabal  [email-masked]
> > > Dept. Electrical & Computer Eng.
> > > McGill University 
> > > 
> > 
> > _________________________________________________________
> > DO YOU YAHOO!?
> > Get your free @yahoo.com address at http://mail.yahoo.com
> > 
> > 
> 

_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com