public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: "J. J. Farrell" <jjf@bcs.org.uk>
To: corinna.vinschen@cityweb.de (Corinna Vinschen)
Cc: cgf@cygnus.com, earnie_boyd@yahoo.com, kabal@ece.mcgill.ca,
	cygwin@sourceware.cygnus.com
Subject: Re: Cygwin B20 - fseek under gcc fails to reposition on text files
Date: Wed, 17 Feb 1999 13:46:00 -0000	[thread overview]
Message-ID: <199902172144.NAA02663@aleph.ssd.hal.com> (raw)
In-Reply-To: < 36CA92B5.844635AA@cityweb.de > from "Corinna Vinschen" at Feb 17, 99 10:58:13 am

> From: Corinna Vinschen <corinna.vinschen@cityweb.de>
> 
> Christopher Faylor wrote:
> > 
> > On Tue, Feb 16, 1999 at 07:41:34AM -0800, Earnie Boyd wrote:
> > >
> > >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
> > >[...]
> 
> This is the _documentation_ of M$. In fact their code doesn't do the right
> thing! As the ftell of newlib, it works without special calls of the
> underlying OS, only calls to `_lseek()' are performed.  The only difference
> between M$ and newlib is, that M$ performs additional counting of \n in
> case of text file processing. It's done in the already translated buffer,
> so the result is crap, as in newlib. Only their hit count is better.
> 
> We have three possible choices:
> 
> 1st: We are not performing the same errors as M$. We do our own, so we let
>      it as it is.
> 
> 2nd: M$-compatible errors, so we let ftell count \n, too. This would result
>      in more often correct telling.
> 
> 3rd: The full stdio code in newlib has to be changed. The buffer is used
>      anyway in binary mode, every call has to use new counting and
>      translation methods than the current one.
>      Because this has to be done _very_ cautious, it's a long time change.
> 
> For the near future, I would prefer the second choice. Other opinions?

This isn't just a question of compatibility with MS, it's one of
conformance to Standard C - we should aim to get it right, in the
long term at least, whether we like it or not!

Here are a couple of extracts from C89 which describe how this
lot should work on text streams - it's perhaps safer to base an
implementation on what comes from the horse's mouth rather than
what MS's documentation says, though MS looks basically OK in
this case:

   4.9.9.2  int fseek(FILE *stream, long int offset, int whence)

   For a text stream, either <offset> shall be zero, or <offset>
   shall be a value returned by an earlier call to the <ftell>
   function on the same stream and <whence> shall be <SEEK_SET>.


   4.9.9.4  long int ftell(FILE *stream)

   The <ftell> function obtains the current value of the file
   position indicator for the stream pointed to by <stream>. 
   For a text stream, its file position indicator contains
   unspecified information, usable by the <fseek> function for
   returning the file position indicator for the stream to its
   position at the time of the <ftell> call; the difference
   between two such return values is not necessarily a meaningful
   measure of the number of characters written or read.

Do we do fgetpos/fsetpos right for both binary and text? The
definition of ftell/fseek for text is essentially the same as
fgetpos/fsetpos for both types - so I would guess there's either
a problem with fgetpos/fsetpos as well, or we could pinch
something from it for the ftell/fseek text case.


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

WARNING: multiple messages have this Message-ID
From: "J. J. Farrell" <jjf@bcs.org.uk>
To: corinna.vinschen@cityweb.de (Corinna Vinschen)
Cc: cgf@cygnus.com, earnie_boyd@yahoo.com, kabal@ece.mcgill.ca,
	cygwin@sourceware.cygnus.com
Subject: Re: Cygwin B20 - fseek under gcc fails to reposition on text files
Date: Sun, 28 Feb 1999 23:02:00 -0000	[thread overview]
Message-ID: <199902172144.NAA02663@aleph.ssd.hal.com> (raw)
Message-ID: <19990228230200.UOBmAv8gaii-2TFzlB062BAp8qIZjMXZhhO-AtK9vMc@z> (raw)
In-Reply-To: <36CA92B5.844635AA@cityweb.de>

> From: Corinna Vinschen <corinna.vinschen@cityweb.de>
> 
> Christopher Faylor wrote:
> > 
> > On Tue, Feb 16, 1999 at 07:41:34AM -0800, Earnie Boyd wrote:
> > >
> > >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
> > >[...]
> 
> This is the _documentation_ of M$. In fact their code doesn't do the right
> thing! As the ftell of newlib, it works without special calls of the
> underlying OS, only calls to `_lseek()' are performed.  The only difference
> between M$ and newlib is, that M$ performs additional counting of \n in
> case of text file processing. It's done in the already translated buffer,
> so the result is crap, as in newlib. Only their hit count is better.
> 
> We have three possible choices:
> 
> 1st: We are not performing the same errors as M$. We do our own, so we let
>      it as it is.
> 
> 2nd: M$-compatible errors, so we let ftell count \n, too. This would result
>      in more often correct telling.
> 
> 3rd: The full stdio code in newlib has to be changed. The buffer is used
>      anyway in binary mode, every call has to use new counting and
>      translation methods than the current one.
>      Because this has to be done _very_ cautious, it's a long time change.
> 
> For the near future, I would prefer the second choice. Other opinions?

This isn't just a question of compatibility with MS, it's one of
conformance to Standard C - we should aim to get it right, in the
long term at least, whether we like it or not!

Here are a couple of extracts from C89 which describe how this
lot should work on text streams - it's perhaps safer to base an
implementation on what comes from the horse's mouth rather than
what MS's documentation says, though MS looks basically OK in
this case:

   4.9.9.2  int fseek(FILE *stream, long int offset, int whence)

   For a text stream, either <offset> shall be zero, or <offset>
   shall be a value returned by an earlier call to the <ftell>
   function on the same stream and <whence> shall be <SEEK_SET>.


   4.9.9.4  long int ftell(FILE *stream)

   The <ftell> function obtains the current value of the file
   position indicator for the stream pointed to by <stream>. 
   For a text stream, its file position indicator contains
   unspecified information, usable by the <fseek> function for
   returning the file position indicator for the stream to its
   position at the time of the <ftell> call; the difference
   between two such return values is not necessarily a meaningful
   measure of the number of characters written or read.

Do we do fgetpos/fsetpos right for both binary and text? The
definition of ftell/fseek for text is essentially the same as
fgetpos/fsetpos for both types - so I would guess there's either
a problem with fgetpos/fsetpos as well, or we could pinch
something from it for the ftell/fseek text case.


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


  parent reply	other threads:[~1999-02-17 13:46 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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
  -- 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  5:27 Earnie Boyd
1999-02-28 23:02 ` Earnie Boyd
1999-02-16  4:24 Peter Kabal
1999-02-28 23:02 ` Peter Kabal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199902172144.NAA02663@aleph.ssd.hal.com \
    --to=jjf@bcs.org.uk \
    --cc=cgf@cygnus.com \
    --cc=corinna.vinschen@cityweb.de \
    --cc=cygwin@sourceware.cygnus.com \
    --cc=earnie_boyd@yahoo.com \
    --cc=kabal@ece.mcgill.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).