Binary I/O on stdin/stdout?
Brian Campbell
brianc at cognos.uucp
Wed Apr 6 04:43:41 AEST 1988
In article <4250 at hoptoad.uucp> gnu at 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 at 1:163/8
More information about the Comp.lang.c
mailing list