www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/03/11/12:24:59

Date: Mon, 11 Mar 1996 19:01:17 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Brendan Simon <brendan AT rdt DOT monash DOT edu DOT au>
Cc: djgpp-announce AT delorie DOT com
Subject: Re: grep bug
In-Reply-To: <313E0ECE.4A73@rdt.monash.edu.au>
Message-Id: <Pine.SUN.3.91.960311185441.6853A-100000@is>
Mime-Version: 1.0

On Thu, 7 Mar 1996, Brendan Simon wrote:

> > On Wed, 6 Mar 1996, Brendan Simon wrote:
> > 
> > > If a list of files not in the command line arguments, then my machine
> > > halts and I have to reboot it.  Not even control-C or control-break
> > > will kill it.  Control-Alt-Delete works (I think, not 100% sure)

This is a bug in the DOS port of Grep.  It calls `setmode' on the standard
input, even if that is a console.  But there is no way to terminate binary
reads from the console by any special character (binary reads don't treat
any character as special), Ctrl-C is disabled after the call to `setmode'
and Ctrl-Break won't be seen until the `read' call returns, because you
are parked in a DOS call in real mode.  So it's stuck. 

Here is the patch to fix it:

*** grep.c~0	Tue Sep 26 12:07:08 1995
--- grep.c	Mon Mar 11 18:37:58 1996
*************** main(argc, argv)
*** 847,853 ****
  	  {
  #ifdef  __MSDOS__
              /* This allows to grep through binary files, even from a pipe. */
!             setmode(desc, O_BINARY);
  #endif
  	    filename = desc == 0 ? "(standard input)" : argv[optind];
  	    count = grep(desc);
--- 847,854 ----
  	  {
  #ifdef  __MSDOS__
              /* This allows to grep through binary files, even from a pipe. */
!             if (!isatty(desc))
!               setmode(desc, O_BINARY);
  #endif
  	    filename = desc == 0 ? "(standard input)" : argv[optind];
  	    count = grep(desc);
*************** main(argc, argv)
*** 874,880 ****
      {
        filename = "(standard input)";
  #ifdef  __MSDOS__
!       setmode(0, O_BINARY);
  #endif
        count = grep(0);
        if (count_matches)
--- 875,882 ----
      {
        filename = "(standard input)";
  #ifdef  __MSDOS__
!       if (!isatty(0))
!         setmode(0, O_BINARY);
  #endif
        count = grep(0);
        if (count_matches)

- Raw text -


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