Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #16933

Re: stream functions

From Nobody <nobody@nowhere.com>
Subject Re: stream functions
Date 2012-02-08 19:43 +0000
Message-Id <pan.2012.02.08.19.43.27.33000@nowhere.com>
Newsgroups comp.lang.c
References (2 earlier) <4f31b446$0$1075$bbae4d71@news.suddenlink.net> <4f31b4b3$0$593$bbae4d71@news.suddenlink.net> <4f31d254$0$18693$91cee783@newsreader03.highway.telekom.at> <lnhaz2m4k5.fsf@nuthaus.mib.org> <4f31edb5$0$32580$bbae4d71@news.suddenlink.net>
Organization Zen Internet

Show all headers | View raw


On Tue, 07 Feb 2012 22:36:23 -0500, Bill Cunningham wrote:

>> And except for systems based on neither Unix nor MS-DOS/Windows, where
>> the distinction between binary and text files might be even more
>> significant.  C's stdio is very deliberately designed to work on such
>> systems.
> 
>     What do you mean for example Keith? I know for portability to use "rb" 
> and "wb" but is there even more distinction you say from binary and text 
> files?

fseek() and ftell() have some weirdness with files opened in text mode on
platforms where text and binary modes differ. E.g. for Windows:

    http://msdn.microsoft.com/en-us/library/75yw9bf3%28v=vs.71%29.aspx

    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 a
    file that ends with a CTRL+Z may cause fseek to behave improperly near
    the end of the file.

My system with a copy of the C99 standard isn't to hand, but I'm fairly
sure that the standard says something similar, i.e. that fseek/ftell have
well-defined behaviour when used on binary streams but a large amount of
undefined behaviour when used on text streams.

> I think Unix treats everything like a text file.

Unix uses a bare LF ('\n') as its EOL indicator and doesn't have an EOF
indicator, so there's no distinction between text and binary files on Unix
(i.e. there's no difference between "r" and "rb", etc).

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

stream functions "Bill Cunningham" <nospam@nspam.invalid> - 2012-02-07 16:50 -0500
  Re: stream functions John Gordon <gordon@panix.com> - 2012-02-07 23:07 +0000
    Re: stream functions "Bill Cunningham" <nospam@nspam.invalid> - 2012-02-07 18:31 -0500
      Re: stream functions "Bill Cunningham" <nospam@nspam.invalid> - 2012-02-07 18:33 -0500
        Re: stream functions Johann Klammer <klammerj@NOSPAM.a1.net> - 2012-02-08 02:39 +0100
          Re: stream functions Keith Thompson <kst-u@mib.org> - 2012-02-07 18:39 -0800
            Re: stream functions "Bill Cunningham" <nospam@nspam.invalid> - 2012-02-07 22:36 -0500
              Re: stream functions Nobody <nobody@nowhere.com> - 2012-02-08 19:43 +0000
          Re: stream functions Barry Schwarz <schwarzb@dqel.com> - 2012-02-07 21:01 -0800
      Re: stream functions John Gordon <gordon@panix.com> - 2012-02-08 15:13 +0000
        Re: stream functions "Bill Cunningham" <nospam@nspam.invalid> - 2012-02-08 15:54 -0500
          Re: stream functions John Gordon <gordon@panix.com> - 2012-02-08 21:09 +0000
            Re: stream functions "Bill Cunningham" <nospam@nspam.invalid> - 2012-02-08 17:37 -0500
              Re: stream functions John Gordon <gordon@panix.com> - 2012-02-08 23:16 +0000
                Re: stream functions Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-02-13 02:14 -0800
                Re: stream functions James Kuyper <jameskuyper@verizon.net> - 2012-02-13 05:53 -0500
                Re: stream functions Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-02-13 03:23 -0800
                Re: stream functions Markus Wichmann <nullplan@gmx.net> - 2012-02-14 21:50 +0100
              Re: stream functions "Heinrich Wolf" <invalid@invalid.invalid> - 2012-02-09 10:45 +0100
                Re: stream functions "Bill Cunningham" <nospam@nspam.invalid> - 2012-02-09 22:37 -0500
          Re: stream functions Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-02-13 02:17 -0800
      Re: stream functions gordonb.qxgs4@burditt.org (Gordon Burditt) - 2012-02-13 01:03 -0600
        Re: stream functions Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-02-13 08:23 +0000
        Re: stream functions Keith Thompson <kst-u@mib.org> - 2012-02-13 02:06 -0800
        Re: stream functions David Thompson <dave.thompson2@verizon.net> - 2012-02-18 23:12 -0500

csiph-web