Sender: nate AT cartsys DOT com Message-ID: <35DF22AA.7761E41C@cartsys.com> Date: Sat, 22 Aug 1998 12:57:30 -0700 From: Nate Eldredge MIME-Version: 1.0 To: "John M. Aldrich" CC: Michel de Ruiter , djgpp-workers AT delorie DOT com Subject: Re: stat c:/con References: <35DB610F DOT 38AAAFC8 AT cs DOT net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk John M. Aldrich wrote: > > It's not a bug, it's a feature. "con" is a special device name under > MS-DOS that refers to the system console, i.e., the keyboard and primary > display. If you try to stat it or manipulate it, you may get unintended > results. DJGPP programs (correctly) pass along any such requests to the > DOS file handler, which (correctly) assumes that you meant to read from > or write to the console, and acts accordingly. Other device names > include "NUL", "AUX", "PRN", "COM1"-"COM4", and "LPT1"-"LPT4". One > somewhat invisible quirk of DOS is that these special devices are > assumed to be present in every directory, which is why you can access > them with "c:/con". > > I'm not sure why stat() tries to read from the file in question; it may > or may not be a bug. In any case, what happens is that, when you type > in some text, it goes into the internal DOS file buffer representing the > console, and is not actually _read_ by your program; merely examined. > However, when a subsequent program tries to read from the console, it > gets whatever you typed before because the buffer wasn't ever cleared. > > Any comments from the other "workers" on this? :-) I think I see the problem. In order to get the execute bit right, `stat' calls `_is_executable' on any file which isn't a directory (directories have the execute bit set, Unix-style). See line 600 or so of stat.c. This, of course, reads some bytes from the file to find its magic number ("MZ", for instance). And if the file is `con', it reads from the console. IMHO, this is a bug. Either `stat' should avoid calling `_is_executable' on devices, or `_is_executable' should fail immediately, without reading, when presented with a file that's really a device. I'm not sure which is better. -- Nate Eldredge nate AT cartsys DOT com