Subject: Re: Problem with stdout BINARY
From: [email-masked] (Jason Hickey)

12 Jun 1997 23:54:48 -0700
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
References: <[email-masked]>
Original-To: [email-masked] (Cygnus gnuwin32)
In-Reply-To: <[email-masked]>
X-Face: $tsnqT``tn7U3/uW*Z+d=O5bh1'T^86$3I(2EL0^#]<th-'d?|vJ")-$aJX?#bR|@%BNUb/
	`1r-eC{-5.[YSA&,: {b#V4y-,SS5&!-}NuZ$MR[D6Fl@Ub/>WvS6~GV41O5CQlf2}8#N,m>DFK}Ya`
	Wux,YSwY~w|CyQF?y1xruG]qR%BxY=Wcs)?|/
Original-Sender: [email-masked]

Blake McBride writes:
 > At 11:29 AM 6/11/97 +0100, you wrote:
 > >Hi everybody,
 > >
 > >Trying to write gif file in stdout with 'putchar'. b18 seems to add a CRNL
 > >every CR he
 > >founds in the file.
 > 
 > You know it's one of life's great mysteries.  stdxxx used to be opened in
 > binary mode and then someone changed it.   It seems to me that it's got
 > to be trivial to switch it back.  The reason for changing it is unknown
 > to me.  Since they've changed it to TEXT mode you can't even execute:
 > 
 > gzip -dc abc.tar.gz |tar xvf -
 > 
 > anymore.  I don't have time to find and fix the problem for my own use
 > and this is the only reason I don't use gnu-win32.
 > 
 > --blake

I've run into the same problem--for instance, if "x" is a binary file,
the commands "dd if=x of=y" and "dd if=x > y" produce different
results ("cat x > y" doesn't work because cat opens its input in TEXT
mode).  This is an incredible headache, but the fix is pretty easy.

You need to recompile bash, which always opens redirects in TEXT mode.
You can download my patched copy of bash at

    http://www.cs.cornell.edu/home/jyh/cygwin32/

or you can just patch the file "make_cmd.c" with the following patch:

*** make_cmd.c	Thu Jun 12 10:22:38 1997
--- x	Thu Jun 12 11:02:02 1997
***************
*** 467,494 ****
  
      case r_output_direction:	/* >foo */
      case r_output_force:	/* >| foo */
- #ifndef TEXT_MODE
-       temp->flags = O_TRUNC | O_WRONLY | O_CREAT | O_BINARY;
- #else
        temp->flags = O_TRUNC | O_WRONLY | O_CREAT;
- #endif
        break;
  
      case r_input_direction:	/* <foo */
      case r_inputa_direction:	/* foo & makes this. */
- #ifndef TEXT_MODE
-       temp->flags = O_RDONLY | O_BINARY;
- #else
        temp->flags = O_RDONLY;
- #endif
        break;
  
      case r_appending_to:	/* >>foo */
- #ifndef TEXT_MODE
-       temp->flags = O_APPEND | O_WRONLY | O_CREAT | O_BINARY;
- #else
        temp->flags = O_APPEND | O_WRONLY | O_CREAT;
- #endif
        break;
  
      case r_deblank_reading_until: /* <<-foo */
--- 467,482 ----
***************
*** 503,521 ****
        break;
      
      case r_err_and_out:		/* command &>filename */
- #ifndef TEXT_MODE
-       temp->flags = O_TRUNC | O_WRONLY | O_CREAT | O_BINARY;
- #else
        temp->flags = O_TRUNC | O_WRONLY | O_CREAT;
- #endif
        break;
  
      case r_input_output:
- #ifndef TEXT_MODE
-       temp->flags = O_RDWR | O_CREAT | O_BINARY;
- #else
        temp->flags = O_RDWR | O_CREAT;
- #endif
        break;
  
      default:
--- 491,501 ----

--
Jason Hickey			Email: [email-masked]
Department of Computer Science	Tel: (607) 255-1372
Cornell University

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".