Binary I/O on stdin/stdout?
Richard A. O'Keefe
ok at quintus.UUCP
Sat Apr 2 14:20:54 AEST 1988
In article <4296 at hoptoad.uucp>, gnu at hoptoad.uucp (John Gilmore) writes:
> karl at haddock.ISC.COM (Karl Heuer) wrote:
> > In article <8036 at elsie.UUCP> ado at elsie.UUCP (Arthur David Olson) writes:
> > >> > There seems to be *no way* to "reopen" these streams as binary.
> <image scale .5 .5 | clip 0 40 300 300 | bwdither | lpr -v
> This really works on Unix, and it would be pretty easy to make these
> work on any system that could support binary files as stdin/stdout,
> (and had a shell that would make pipes, like MSDOS or Unix), but not if
> the standard doesn't tell me and those implementers a good way for me
> to say "please sir, don't translate CR to LF on stdin for me, just let
> me at the bytes"...
If UNIX needed this facility, and if it used "b" to indicate binary mode,
FILE *binin = fdopen(fileno(stdin), "rb");
FILE *binout= fdopen(fileno(stdout),"wb");
/* use bin_in, bin_out instead of stdin, stdout */
would do the job. Would this work in MSDOS?
Instead of having a way of switching the mode, why not ask for two more
"standard" streams: binin and binout, where systems which don't need a
distinction between text and binary would identify them with stdin and
stdout, systems where switching is possible would switch as necessary,
and systems where only one method of connexion was allowed would have
all I/O on the "wrong" connexions return EOF, and systems where either
method was allowed but not both would pick it up from the first use.
More information about the Comp.lang.c
mailing list