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  5:27 Earnie Boyd
  1999-02-28 23:02 ` Earnie Boyd
  0 siblings, 1 reply; 36+ messages in thread
From: Earnie Boyd @ 1999-02-16  5:27 UTC (permalink / raw)
  To: kabal; +Cc: cygwin users

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

^ permalink raw reply	[flat|nested] 36+ messages in thread
* Re: Cygwin B20 - fseek under gcc fails to reposition on text files
@ 1999-02-22 14:28 Earnie Boyd
  1999-02-28 23:02 ` Earnie Boyd
  0 siblings, 1 reply; 36+ messages in thread
From: Earnie Boyd @ 1999-02-22 14:28 UTC (permalink / raw)
  To: cygwin users

---Corinna Vinschen <corinna.vinschen@cityweb.de> wrote:
>
> I don't want to be boring, but shouldn't we return
> to the _subject_ instead of discussing the ability
> (or it's absence) to understand contributing?

The contribution discussion is under a different thread.

> 
> You still know the subject? Three choices? Opinions?

In the short-term option 2 in the long-term option 3.  I believe that
any fix that would allow this to work most of the time with the next
release would be beneficial.  However, this should not be a permanent
solution to the problem and a more long term correct method should be
applied.


> 
> And moreover:
> Isn't this a theme for cygwin-developers???

Probably, but it was brought up here so any resolution created on the
cygwin-developers needs to be posted here.
==
-                        \\||//
-------------------o0O0--Earnie--0O0o-------------------
--                earnie_boyd@yahoo.com               --
-- http://www.freeyellow.com/members5/gw32/index.html --
----------------------ooo0O--O0ooo----------------------

PS: Newbie's, you should visit my page.
_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 36+ messages in thread
* Re: Cygwin B20 - fseek under gcc fails to reposition on text files
@ 1999-02-19  7:00 setera
       [not found] ` < 8525671D.00525F37.00@D51MTA10.pok.ibm.com >
  1999-02-28 23:02 ` setera
  0 siblings, 2 replies; 36+ messages in thread
From: setera @ 1999-02-19  7:00 UTC (permalink / raw)
  To: cygwin

>Currently, Corinna, Mumit, and a couple of other people are the only
>outside contributers to the project.  Everyone else seems to be in
>"Cygwin doesn't work the way I think it should when I run program X.
>Here's the error message." mode.
>
>I'm collecting the error messages and hope to investigate problems but
>the reality is that this is a volunteer effort for DJ and me.  Our
>real jobs don't offer much time for tracking down net problems.

Chris,

I can certainly understand your frustrations.  In my GIMP work, I've had a
heck of a time with some hanging problems which I've reported to you.  I
report them to you and DJ not because I *expect* you to jump and fix them,
but because I am clueless on how to fix them myself.  I *have* downloaded
the source code and *have* attempted to understand the infrastructure
enough to solve the problems.  In my case at least, if there were more
documentation on the internals of the winsup code, I might be able to solve
some problems on my own.  Unfortunately, I think with the exception of a
few people (you, DJ, Sergey, etc) most do not have a good enough
understanding of the internals of winsup to really be able to help out.  On
the other hand, I try not to complain about things either.

Anyway, just another person's perspective.

Craig


Craig Setera
AS/400 Enterprise Java Development
IBM Rochester
setera@us.ibm.com
(507) 253-3387 - Tie: 553-3387




--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 36+ messages in thread
* 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; 36+ 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] 36+ messages in thread
* Cygwin B20 - fseek under gcc fails to reposition on text files
@ 1999-02-16  4:24 Peter Kabal
  1999-02-28 23:02 ` Peter Kabal
  0 siblings, 1 reply; 36+ messages in thread
From: Peter Kabal @ 1999-02-16  4:24 UTC (permalink / raw)
  To: cygwin

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 

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

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

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-16  5:27 Cygwin B20 - fseek under gcc fails to reposition on text files Earnie Boyd
1999-02-28 23:02 ` Earnie Boyd
  -- strict thread matches above, loose matches on Subject: below --
1999-02-22 14:28 Earnie Boyd
1999-02-28 23:02 ` Earnie Boyd
1999-02-19  7:00 setera
     [not found] ` < 8525671D.00525F37.00@D51MTA10.pok.ibm.com >
1999-02-19 17:21   ` Christopher Faylor
1999-02-22 13:40     ` Corinna Vinschen
1999-02-28 23:02       ` Corinna Vinschen
1999-02-28 23:02     ` Christopher Faylor
1999-02-28 23:02 ` setera
1999-02-16  7:41 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-28 23:02                 ` Christopher Faylor
1999-02-28 23:02           ` Corinna Vinschen
1999-02-28 23:02       ` Corinna Vinschen
1999-02-28 23:02     ` Christopher Faylor
1999-02-28 23:02 ` Earnie Boyd
1999-02-16  4:24 Peter Kabal
1999-02-28 23:02 ` Peter Kabal

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).