Subject: Re: ASCII and BINARY files. Why?
From: [email-masked] (Alex Stewart)

31 Jan 1997 00:29:42 -0800
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Original-To: [email-masked] (Geoffrey Noer)
Original-Cc: [email-masked]
In-Reply-To: <[email-masked]> from "Geoffrey Noer" at Jan 27, 97 09:32:46 pm
X-Mailer: ELM [version 2.4 PL23]
Content-Length: 2353      
Original-Sender: [email-masked]

> I agree completely with what was said here.  The text/binary problem
> is solveable but requires a small amount of work on each and every
> Unix program ported.  If I could assume binary mode and fix everything at
> the expense of violating the ANSI standards, I might well go ahead and
> do so.  However, assuming either mode makes some programs happy at the
> expense of others which is why we've stuck to the ANSI specs and made
> text mode the default for I/O.

It would be easier for some types of programs if there were some basic
mechanisms in the header files/libraries for automating some of it (see my
comment below)..

> FYI, in the case of pipes, the program opening the pipe is responsible for
> calling the cygwin32 setmode(fd, mode) function.  See bash/execute_cmd.c
> for an example as to how to use it.  The implementation is in
> winsup/syscalls.cc.

Might I make a suggestion here?  The issue of modes on pipes would be much less
of a problem if the mechanism for converting between DOS/Win text and C native
text were a 1:1 mapping (i.e. NL->CRLF, CRLF->NL, CR->CR(always), (and LF->NL,
but that's a side-issue)).  This way, if I want to pipe "gzip -dc file | tar
xvf -" (as I often do), it wouldn't matter what mode the pipe was created in as
long as it was the same mode on both ends, because any changes introduced in a
C->text conversion would be exactly reversed in the text->C conversion on the
other end of the pipe.

Of course this doesn't help as much with redirection to files (thought it would
under a few circumstances)..  it would also be nice if there was a way to
specify on the compiler command line (with a define or something) whether file
IO should assume text or binary mode.. this would make it easy to fix with a
single command-line switch many programs (such as gzip) which should always do
binary IO anyway.  It would probably be a good idea for any program which works
with binary files in general to call setmode on its stdin/stdout handles itself
(I'm assuming Cygwin32 allows this.. if it doesn't it certainly should) anyway.

-alex
-------------------------------------------------------------------------------
     Alex Stewart - [email-masked] - Richelieu @ Diversity University MOO
                         http://www.crl.com/~riche
           "For the world is hollow, and I have touched the sky."
-
For help on using this list, send a message to
"[email-masked]" with one line of text: "help".