Path: utzoo!utgpu!water!watmath!clyde!rutgers!gatech!bloom-beacon!tut.cis.ohio-state.edu!mailrus!ames!pasteur!ucbvax!hoptoad!gnu From: gnu@hoptoad.uucp (John Gilmore) Newsgroups: comp.lang.c Subject: Binary I/O on stdin/stdout? Message-ID: <4250@hoptoad.uucp> Date: 27 Mar 88 12:06:53 GMT References: <302@goofy.megatest.UUCP> <225800017@uxe.cso.uiuc.edu> <7550@brl-smoke.ARPA> Organization: Grasshopper Group in San Francisco Lines: 23 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@toad.com "Watch me change my world..." -- Liquid Theatre