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]

nested popen()'s lead to fgets() failure on 64-bit only


Hi,

The program below works just fine on 32-bit Cygwin:
  buf1 = /usr/bin/file.exe
  buf2 = /usr/bin/file.exe: application/x-dosexec

But on 64-bit Cygwin (2.831), the second fgets() fails:
  buf1 = /usr/bin/file.exe
fgets2: No error

It only seems to happen with nested popen()'s.  Is it due to a
problem in the Cygwin lib?

Thanks,
David


#include <stdio.h>

int
main() {
  FILE *f1, *f2;

  if ((f1 = popen("ls /usr/bin/file.exe", "r"))) {
    char buf1[BUFSIZ];

    while (fgets(buf1, sizeof buf1, f1)) {
      printf("  buf1 = %s", buf1);

      if ((f2 = popen("file --mime-type /usr/bin/file.exe", "r"))) {
        char buf2[BUFSIZ];

        /* This fgets call fails on 64-bit Cygwin, with "No error". */
        if (fgets(buf2, sizeof buf2, f2)) {
          printf("  buf2 = %s", buf2);
        } else {
          perror("fgets2");
        }

        pclose(f2);
      } else {
        perror("popen2");
      }
    }

    pclose(f1);
  } else {
    perror("popen1");
  }

  return 0;
}

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


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