Path: utzoo!dciem!nrcaer!cognos!brianc From: brianc@cognos.uucp (Brian Campbell) Newsgroups: comp.lang.c Subject: Re: Binary I/O on stdin/stdout? Message-ID: <2662@cognos.UUCP> Date: 5 Apr 88 18:43:41 GMT Article-I.D.: cognos.2662 Posted: Tue Apr 5 13:43:41 1988 References: <302@goofy.megatest.UUCP> <225800017@uxe.cso.uiuc.edu> <7550@brl-smoke.ARPA> <4250@hoptoad.uucp> Reply-To: brianc@cognos.UUCP (Brian Campbell) Organization: Cognos Incorporated, Ottawa, Canada Lines: 25 In article <4250@hoptoad.uucp> gnu@hoptoad.uucp (John Gilmore) writes: ! 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? Is this a portable concept? ! * 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"). As Doug Gwyn pointed out, this makes no difference on POSIX-conforming systems. Under DOS, however, both the Borland and Microsoft C libraries include a setmode(int fd, unsigned mode) function. The mode parameter is pretty much the same as that of creat() with the addition of two other masks: O_BINARY and O_TEXT. -- Brian Campbell uucp: decvax!utzoo!dciem!nrcaer!cognos!brianc Cognos Incorporated mail: POB 9707, 3755 Riverside Drive, Ottawa, K1G 3Z4 (613) 738-1440 fido: (613) 731-2945 300/1200, sysop@1:163/8