delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/01/12/15:15:17

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/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
To: cygwin AT cygwin DOT com
Subject: stderr ?= stdout
Mail-Copies-To: never
Reply-To: sds AT gnu DOT org
X-Attribution: Sam
X-Disclaimer: You should not expect anyone to agree with me.
From: Sam Steingold <sds AT gnu DOT org>
Mail-Followup-To: cygwin AT cygwin DOT com
Date: Wed, 12 Jan 2005 15:14:54 -0500
Message-ID: <u1xcq2ym9.fsf@gnu.org>
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/21.3.50 (windows-nt)
MIME-Version: 1.0

How do I check whether stdout==stderr or not?
e.g., I want to distinguish between these situations:
$ foo
$ foo > log
$ foo 1>log1 2>log2



  struct stat statbuf1;
  struct stat statbuf2;
  fstat(handle1,&statbuf1)
  fstat(handle2,&statbuf2)
  if (statbuf1.st_dev == statbuf2.st_dev
     && statbuf1.st_ino == statbuf2.st_ino) {
    /* handle1 and handle2 point to the same inode. */
    if ((S_ISREG(statbuf1.st_mode) || S_ISBLK(statbuf1.st_mode))
        && (S_ISREG(statbuf2.st_mode) || S_ISBLK(statbuf2.st_mode))) {
      /* handle1 and handle2 are exchangeable only if they are positioned
         at the same file position. */
      off_t pos1 = lseek(handle1,0,SEEK_CUR);
      if (pos1 >= 0) {
        off_t pos2 = lseek(handle2,0,SEEK_CUR);
        if (pos2 >= 0) 
          return (pos1 == pos2);
      }
    }
    return true;
  } else 
    return false;
 
alas, the current cygwin reports different inodes for stdout and stderr:
  -437397064 and 593767114
so, what is the right way to check that two FDs refer to the
same device?

Thanks!

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.honestreporting.com>
Beliefs divide, doubts unite.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.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