public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* RE: Cygwin B20 - fseek under gcc fails to reposition on text files
@ 1999-02-16  7:41 Earnie Boyd
       [not found] ` < 19990216154134.3413.rocketmail@send104.yahoomail.com >
  1999-02-28 23:02 ` Earnie Boyd
  0 siblings, 2 replies; 64+ messages in thread
From: Earnie Boyd @ 1999-02-16  7:41 UTC (permalink / raw)
  To: Peter Kabal; +Cc: cygwin users

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 <kabal@ece.mcgill.ca> 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:earnie_boyd@yahoo.com ]
> > Sent: February 16, 1999 8:28 AM
> > To: kabal@ece.mcgill.ca
> > 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 <kabal@ECE.McGill.CA> 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  kabal@ECE.McGill.CA
> > > 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

^ permalink raw reply	[flat|nested] 64+ messages in thread

end of thread, other threads:[~1999-02-28 23:02 UTC | newest]

Thread overview: 64+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-16  7:41 Cygwin B20 - fseek under gcc fails to reposition on text files Earnie Boyd
     [not found] ` < 19990216154134.3413.rocketmail@send104.yahoomail.com >
1999-02-16 17:52   ` Christopher Faylor
     [not found]     ` < 19990216205243.L16511@cygnus.com >
1999-02-16 18:18       ` DJ Delorie
1999-02-28 23:02         ` DJ Delorie
1999-02-17  2:01     ` Corinna Vinschen
     [not found]       ` < 36CA92B5.844635AA@cityweb.de >
1999-02-17  8:07         ` DJ Delorie
1999-02-28 23:02           ` DJ Delorie
1999-02-17 13:46         ` J. J. Farrell
1999-02-28 23:02           ` J. J. Farrell
1999-02-17  9:36       ` Re[2]: " Paul Sokolovsky
     [not found]         ` < 17817.990217@is.lg.ua >
1999-02-17 10:07           ` DJ Delorie
     [not found]             ` < 199902171807.NAA16764@envy.delorie.com >
1999-02-17 19:16               ` Larry Hall
     [not found]                 ` < 3.0.5.32.19990217221306.0162b070@pop.ma.ultranet.com >
1999-02-17 19:19                   ` DJ Delorie
     [not found]                     ` < 199902180318.WAA20394@envy.delorie.com >
1999-02-17 20:13                       ` Larry Hall
1999-02-28 23:02                         ` Larry Hall
1999-02-28 23:02                     ` DJ Delorie
1999-02-28 23:02                 ` Larry Hall
1999-02-28 23:02             ` DJ Delorie
1999-02-17 13:37         ` Corinna Vinschen
1999-02-19  2:30           ` Re[2]: " Paul Sokolovsky
     [not found]             ` < 17776.990218@is.lg.ua >
1999-02-19  6:36               ` Christopher Faylor
1999-02-22  3:26                 ` Re[2]: " Paul Sokolovsky
     [not found]                   ` < 13561.990222@is.lg.ua >
1999-02-22  8:55                     ` Cygwin participation threshold DJ Delorie
     [not found]                       ` < 199902221654.LAA07362@envy.delorie.com >
1999-02-22 10:33                         ` Carl Zmola
     [not found]                           ` < 19990222183222023.AAA254@carl_zmola >
1999-02-22 11:21                             ` Fergus Henderson
1999-02-28 23:02                               ` Fergus Henderson
1999-02-22 12:32                             ` DJ Delorie
1999-02-28 23:02                               ` DJ Delorie
1999-02-24  0:08                             ` Christopher Faylor
     [not found]                               ` < 19990223214848.A23525@cygnus.com >
1999-02-24  5:51                                 ` Fergus Henderson
     [not found]                                   ` < 19990225005148.53402@mundook.cs.mu.OZ.AU >
1999-02-24  9:18                                     ` Christopher Faylor
1999-02-24 19:23                                       ` Weiqi Gao
     [not found]                                         ` < 36D4C298.32C1C355@a.crl.com >
1999-02-25  0:23                                           ` Fergus Henderson
1999-02-25  6:01                                             ` Weiqi Gao
1999-02-25 13:48                                               ` Re[2]: " Paul Sokolovsky
1999-02-28 23:02                                                 ` Paul Sokolovsky
1999-02-28 23:02                                               ` Weiqi Gao
1999-02-28 23:02                                             ` Fergus Henderson
1999-02-28 23:02                                         ` Weiqi Gao
     [not found]                                       ` < 19990224121846.A25762@cygnus.com >
1999-02-25  0:14                                         ` Fergus Henderson
     [not found]                                           ` < 19990225191420.16813@mundook.cs.mu.OZ.AU >
1999-02-25  1:00                                             ` Lam Pui Yuen
     [not found]                                               ` < Pine.BSI.3.95.990225170005.16688A-100000@topaz.hknet.com >
1999-02-25  1:09                                                 ` Lam Pui Yuen
1999-02-28 23:02                                                   ` Lam Pui Yuen
1999-02-28 23:02                                               ` Lam Pui Yuen
1999-02-28 23:02                                           ` Fergus Henderson
1999-02-28 23:02                                       ` Christopher Faylor
1999-02-28 23:02                                   ` Fergus Henderson
1999-02-24 10:37                                 ` Carl Zmola
     [not found]                                   ` < 19990224183738302.AAA218@carl_zmola >
1999-02-24 10:44                                     ` Christopher Faylor
     [not found]                                       ` < 19990224134450.B26262@cygnus.com >
1999-02-24 10:48                                         ` Carl Zmola
1999-02-28 23:02                                           ` Carl Zmola
1999-02-28 23:02                                       ` Christopher Faylor
1999-02-28 23:02                                   ` Carl Zmola
1999-02-28 23:02                               ` Christopher Faylor
1999-02-28 23:02                           ` Carl Zmola
1999-02-28 23:02                       ` DJ Delorie
1999-02-28 23:02                   ` Re[2]: Cygwin B20 - fseek under gcc fails to reposition on text files Paul Sokolovsky
1999-02-28 23:02                 ` Christopher Faylor
1999-02-28 23:02             ` Re[2]: " Paul Sokolovsky
1999-02-28 23:02           ` Corinna Vinschen
1999-02-28 23:02         ` Re[2]: " Paul Sokolovsky
1999-02-28 23:02       ` Corinna Vinschen
1999-02-28 23:02     ` Christopher Faylor
1999-02-28 23:02 ` Earnie Boyd

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).