This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

stderr ?= stdout

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;
  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?


Sam Steingold ( running w2k
<> <> <>
<> <>
Beliefs divide, doubts unite.

Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]