Binary I/O on stdin/stdout?
John Gilmore
gnu at hoptoad.uucp
Sun Mar 27 22:06:53 AEST 1988
I was just reading over the standard trying to figure out the differences
between binary and text files and had a few realizations:
* Stdin, stdout, and stderr are assumed to be *text* files.
A program that does binary I/O on them is not portable. So, how does
one fix this?
* There seems to be *no way* to "reopen" these streams as
binary. E.g. how do I write a binary file to the current standard
output? Freopen will redirect stdout to a different named file, but I
just want binary treatment for the existing output file (e.g. the one
specified by the user when they ran "a.out >foo").
PS: In the process I found that, since stdout is a *text* file,
fflush() should not write record boundaries on it. Standard I/O is
allowed to screw around with text files (too much, in my opinion - see
section 4.9.2), but it's not allowed to insert newlines at random
places. Though it is not at all clear what is allowed to happen if you
exceed the system's line length limit, which there seems to be no way
to determine, except that it can't be less than 254.
--
{pyramid,ptsfa,amdahl,sun,ihnp4}!hoptoad!gnu gnu at toad.com
"Watch me change my world..." -- Liquid Theatre
More information about the Comp.lang.c
mailing list