Trouble with binary files?

Jim Weirich wrote:

If Unix never distinguished between text and binary files, what
was the binary mode flag for?

Unix originally didn’t have one. Only has it now for compatibility.

I’ll have to assume you’re correct, as I can’t prove my position.

But I definitely remember being led to believe that EOT was an
end-of-file marker. And I remember wondering how it worked for
binary files, did it store the length in the inode or what?

This was System III, around 1980 (out of date even then).

I’ll have to dig into the old kernel to see how it actually
worked. I only have it in hardcopy, though.

Hal

···

On Fri, 2003-09-19 at 22:10, Hal Fulton wrote:

Steven Jenkins wrote:

Hal Fulton wrote:

If Unix never distinguished between text and binary files, what
was the binary mode flag for?

The ‘b’ modifier was added to ANSI C to support non-Unix execution
environments that distinguish between text and binary files. It didn’t
exist in Unix until ANSI C required it; since then, it’s been a no-op.

4.9 Input/Output

Thanks, Steve.

Very, very frustrating to me when the facts don’t fit my memories…
I still think I was misinformed at some point about EOT and such.

I’m not sure when ANSI C came along, but I think it was after I
learned C and Unix, and after the introduction of the IBM PC.

Have to go look up Tobin Maginnis and see what he says…

Hal

YANAGAWA Kazuhisa graced us by uttering:

For ANSI-C compliance. From fopen(3) of FreeBSD 4.8-RELEASE:

 The mode string can also include the letter ``b'' either
 as a third char- acter or as a character between the
 characters in any of the two-charac- ter strings described
 above.  This is strictly for compatibility with ISO/IEC
 9899:1990 (``ISO C89'') and has no effect; the ``b'' is
 ignored.

I believe most of Unix like platforms stand on a similar
position.

fopen(3) on my Debian box adds:
[…]; the b'' is ignored on all POSIX conforming systems, including Linux. (Other systems may treat text files and binary files differently, and adding the b’’ may be a good
idea if you do I/O to a binary file and expect that your
program may be ported to non-Unix environments.)

If the POSIX standard dictates that ‘b’ is ignored, it must also
dictate that binary and text files are treated identically, no?

[…checking…]

Correct. From the POSIX spec
http://www.opengroup.org/onlinepubs/007904975/toc.htm:

The character 'b' shall have no effect, but is allowed for
ISO C standard conformance.

(That’s the subjunctive mood, so any implementation that is
affected by the ‘b’ flag is not POSIX compliant.)

And from dmr’s “The UNIX Time-Sharing System” (C)1974
http://cm.bell-labs.com/cm/cs/who/dmr/cacm.html:

III. THE FILE SYSTEM
3.1 Ordinary files
A file contains whatever information the user places on it,
for example, symbolic or binary (object) programs. No
particular structuring is expected by the system. A file of
text consists simply of a string of characters, with lines
demarcated by the newline character. Binary programs are
sequences of words as they will appear in core memory when
the program starts executing. A few user programs manipulate
files with more structure; for example, the assembler
generates, and the loader expects, an object file in a
particular format. However, the structure of files is
controlled by the programs that use them, not by the system. 

This seems to be a CPM/DOS/Win32 issue.

Cheers,
Tim Hammerquist

···


Did I mention that I can’t tell you how to get rich?
If I could, I’d be rich, and not here.
– Martien Verbruggen in comp.lang.perl.misc

Hal Fulton wrote:

Very, very frustrating to me when the facts don’t fit my memories…
I still think I was misinformed at some point about EOT and such.

Your batting average is still pretty good.

I’m not sure when ANSI C came along, but I think it was after I
learned C and Unix, and after the introduction of the IBM PC.

The standard was published in 1989. K&R second edition (1988) mentions
the “b” modifier to fopen() (the standard was nearing ratification at
the time), but the first edition (1978) doesn’t.

I remember all this because I was trying to write code in the mid-80s to
run on both BSD Unix and MS-DOS. Turbo C required the “b” modifier or
some library function (binmode()?), but the (pre-gcc) Unix C compiler
didn’t allow them. I had to do it with preprocessor conditionals. Yuck.

I grumble (quietly) when other people carry on off-topic discussions,
and now I’m doing it. We return now to ruby-talk, already in progress.

Steve