delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/07/26/04:31:44

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Fri, 26 Jul 2002 10:30:52 +0200
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: how to check stdin == stdout?
Message-ID: <20020726103052.W3921@cygbert.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <sa0d6tb8rw7 DOT fsf AT glip DOT premonitia DOT com>
Mime-Version: 1.0
In-Reply-To: <sa0d6tb8rw7.fsf@glip.premonitia.com>
User-Agent: Mutt/1.3.22.1i

On Thu, Jul 25, 2002 at 04:38:32PM -0400, Sam Steingold wrote:
> To check that stdin and stdout are the same TTYs,
> I use the following code on UNIX (all flavors)
> 
> #define stdin_handle   0
> #define stdout_handle  1
> 
>       struct stat stdin_stat;
>       struct stat stdout_stat;
>       if ((fstat(stdin_handle,&stdin_stat) >= 0) &&
>           (fstat(stdout_handle,&stdout_stat) >= 0))
>         if ((stdin_stat.st_dev == stdout_stat.st_dev) &&
>             (stdin_stat.st_ino == stdout_stat.st_ino))
>           same_tty = true;
> 
> it works just fine on all UNIX flavors except for cygwin which has
> different inodes:
> 
>         stdin_stat.st_ino =3989447614
>         stdout_stat.st_ino=3413797845
> 
> what's wrong with cygwin?
> or maybe my method is incorrect?
> so how do I check that 0 and 1 are the same tty?

On Cygwin st_ino is worthless as Chris pointed out already.

OTOH you can just use the value of st_dev to figure that out:

	/dev/tty0 -> st_dev = 1280
	/dev/tty1 -> st_dev = 1281
	...

and when running in notty mode in a console window:

	/dev/conin  -> st_dev = 256
	/dev/conout -> st_dev = 256

Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Developer                                mailto:cygwin AT cygwin DOT com
Red Hat, Inc.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


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