cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/08/22/16:57:28

Sender: nate AT cartsys DOT com
Message-ID: <35DF22AA.7761E41C@cartsys.com>
Date: Sat, 22 Aug 1998 12:57:30 -0700
From: Nate Eldredge <nate AT cartsys DOT com>
MIME-Version: 1.0
To: "John M. Aldrich" <fighteer AT cs DOT net>
CC: Michel de Ruiter <mdruiter AT cs DOT vu DOT nl>, djgpp-workers AT delorie DOT com
Subject: Re: stat c:/con
References: <m0z98iZ-000XesC AT sloep06 DOT cs DOT vu DOT nl> <35DB610F DOT 38AAAFC8 AT cs DOT net>

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


- Raw text -


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