This is the mail archive of the
cygwin
mailing list for the Cygwin project.
stderr ?= stdout
- From: Sam Steingold <sds at gnu dot org>
- To: cygwin at cygwin dot com
- Date: Wed, 12 Jan 2005 15:14:54 -0500
- Subject: stderr ?= stdout
- Reply-to: sds at gnu dot org
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/