delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/08/19/19:38:23

Message-ID: <35DB610F.38AAAFC8@cs.net>
Date: Wed, 19 Aug 1998 19:34:39 -0400
From: "John M. Aldrich" <fighteer AT cs DOT net>
Organization: Two pounds of chaos and a pinch of salt.
MIME-Version: 1.0
To: Michel de Ruiter <mdruiter AT cs DOT vu DOT nl>
CC: djgpp-workers AT delorie DOT com
Subject: Re: stat c:/con
References: <m0z98iZ-000XesC AT sloep06 DOT cs DOT vu DOT nl>

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?  :-)

Michel de Ruiter wrote:
> 
> I have encountered a problem with the current implementation of
> `stat'. I think it is a result from a bug in DOS, but I am not sure.
> 
> I run MS-DOS 7.0 without Win95. The problem is inconsistent behaviour
> of statting `c:/con'. I used the following small program:
> 
> #include <sys/stat.h>
> int main(void) {
>   struct stat s;
>   return stat("c:/con", &s);
> }
> 
> When I first run this program, the computer waits for me to input a
> line (which is *not* OK, IMHO). If I type some text and press enter,
> `stat' returns zero, and I am back at the command line, as expected.
> But then, if I run the program again, there is no wait for input. If I
> run it again and again, no input is required for the number of *bytes*
> I typed the first time. So, it seems the text is in some DOS-buffer
> which is read from at every `stat'.
> 
> Also, after the first `stat'ting and typing some text, if I run `cat',
> an empty line is printed, followed by the last part of the typed text.
> If I then end `cat' by typing ^Z, the "buffer" is empty (statting
> requires input) again.

-- 
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I |     mailto:fighteer AT cs DOT net      |
|       ICQ UIN#:  7406319        |   http://www.cs.net/fighteer/   |
| Descent 2: The Infinite Abyss - The greatest Internet game of all |
| time just got better!  This time, you're going all the way down...|
---------------------------------------------------------------------

- Raw text -


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