Date: Wed, 15 Oct 1997 13:33:16 +0200 (IST) From: Eli Zaretskii To: Nate Eldredge cc: djgpp AT delorie DOT com Subject: Re: DOS ugliness affects grep In-Reply-To: <199710150220.TAA04074@adit.ap.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Tue, 14 Oct 1997, Nate Eldredge wrote: > If you use `grep' on a binary file (or on `*' when there are binary files in > the directory), and it finds a matching "line" which contains a ^Z, it will > give a misleading error message about ENOSPC because the count was short. It > will also only print the first part of the "line", before the ^Z. Thanks for reporting. This is a known problem. It is not limited to `grep', though: any program that reads binary files and prints parts thereof to the screen (e.g., `tail' from Textutils), will have the same problem. > This will not occur if you redirect stdout, for obvious reasons. The reason that this doesn't happen with redirected stdin is that `grep' switches it to binary mode, which makes ^Z not special to DOS I/O. `grep' avoids switching the console to binary mode, because doing so has undesirable side-effects (e.g., Ctrl-C doesn't work, so you can't easily interrupt a runaway program). > I realize this is DOS's fault and not DJGPP's, and no workarounds come > immediately to mind. A workaround is of course to redirect the output to a file or a pipe and examine redirected output with a browser (such as Less) which can display binary files. Other than that, the only solution to this problem would involve a lot of code in low-level library functions, because we do want `_write' to return ENOSPC when it fails to write everything (otherwise, a program that copies files to a floppy would loop forever when the floppy fills up). I'm not sure that working around this is worthwhile, but if somebody feels like working on that, please do.