nested popen()'s lead to fgets() failure on 64-bit only
David Levine
levinedl@acm.org
Mon Jan 13 14:36:00 GMT 2014
Corinna wrote:
> That's the version number of the setup-x86_64.exe tool, not the version
> number of Cygwin. Try `uname -r'.
1.7.27(0.271/5/3)
> Maybe you're calling the wrong file command? What's your $PATH set to?
> What if you change your popen call to run /usr/bin/file.exe with full
> path?
>
> if ((f2 = popen("/usr/bin/file --mime-type /usr/bin/file.exe", "r")))
My PATH picks /usr/bin/file, but just to be sure I hard coded it,
and also used it for the first popen(), and also set PATH to /usr/bin:
$ gcc -o nested_popen nested_popen.c -Wall -Wextra && \
PATH=/usr/bin ./nested_popen
buf1 = /usr/bin/file.exe: application/x-dosexec
popen: No error
fgets2 EOF
It shouldn't be at EOF in this case. If I change the
second popen() to open anything, e.g.,
popen("garbage,really", "r"), it still reports success.
We're getting closer?
David
#include <stdio.h>
int
main() {
FILE *f1, *f2;
if ((f1 = popen("file --mime-type /usr/bin/file.exe", "r"))) {
char buf1[BUFSIZ];
while (fgets(buf1, sizeof buf1, f1)) {
printf(" buf1 = %s", buf1);
if ((f2 = popen("/usr/bin/file.exe --mime-type /usr/bin/file.exe",
"r"))) {
char buf2[BUFSIZ];
perror("popen");
/* This fgets call fails on 64-bit Cygwin 1,7.27(0.271/5/3),
with "No error". */
if (fgets(buf2, sizeof buf2, f2)) {
printf(" buf2 = %s", buf2);
} else if (feof (f2)) {
fputs ("fgets2 EOF\n", stderr);
} 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
More information about the Cygwin
mailing list