delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1999/07/25/01:14:48

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
Sender: cygwin-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com
Date: Sun, 25 Jul 1999 15:13:51 +1000
From: Fergus Henderson <fjh AT cs DOT mu DOT OZ DOT AU>
To: Jeffry T Ross <jtr AT mitre DOT org>
Cc: cygwin AT sourceware DOT cygnus DOT com
Subject: Re: Cat and Head Problems with Binary Files
Message-ID: <19990725151351.A9082@murlibobo.cs.mu.OZ.AU>
References: <4 DOT 1 DOT 19990722175718 DOT 00de9820 AT mailhost DOT teknowledge DOT com> <000e01bed529$6000e780$0f8e5381 AT Toeplitz DOT mitre DOT org>
Mime-Version: 1.0
X-Mailer: Mutt 0.95.1i
In-Reply-To: <000e01bed529$6000e780$0f8e5381@Toeplitz.mitre.org>; from Jeffry T Ross on Fri, Jul 23, 1999 at 12:35:29PM -0400

On 23-Jul-1999, Jeffry T Ross <jtr AT mitre DOT org> wrote:
> Randy
> 
> I thought the suggestion to use dd was a good, although a bit excessive
> when one only wants to move bytes from a file to a pipe without any
> conversion. So I tried it:
> 
> dd if=test1 > test2
> test1 was 1296 bytes and test2 became 1301 bytes.
> 
> So then I tried dd directly to a file.
> dd if=test1 of=test2
> this worked fine.
>
> So now I don't suspect cat but the piping and redirection.

I think the symptom that you report above is a bug in `dd'
(i.e. `dd' has not been properly ported to Cygwin).

> The question is how does cygwin implement it's piping and redirection?

By default, stdin, stdout, and stderr are assumed to use text mode.

If a program such as `dd' wishes to use stdin/stdout/stderr in binary
mode, then it should be modified to do so.

The issue here is basically the same as passing extra flags to open()
and fopen() to say that files should be opened in binary mode.
It's a little bit more complicated, though, since stdin/stdout/stderr
are already open.  However, there should be a way of changing the mode
of an already open file.  I don't recall off-hand what it is, though.
(I vaguely recall some mention of a setmode() function, but I could be
way off base with that...)

> Is this problem imposed by the underlying WIN/DOS or is it a bug in BASH?

Bash doesn't know whether the underlying program (e.g. `dd') will use
the stream in text or binary mode, so there's nothing bash can do.
I suppose you could add special syntax for redirection in binary mode,
so that the user could type e.g. "dd if=test1 >@ test2", but
it makes much more sense for it to be the program's responsibility to
use its files in the right mode rather than for this to be the user's
responsibility.

-- 
Fergus Henderson <fjh AT cs DOT mu DOT oz DOT au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh AT 128 DOT 250 DOT 37 DOT 3        |     -- the last words of T. S. Garp.

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019