X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=buildtool.cpp;h=bc6da92d3b6b9865603d5357203e57713dea1646;hb=3266678238e05b3512e7da3a76c84f5ce4c93938;hp=da482971b58b63b27f4eff053ad91f24057f6061;hpb=c8873dd749805443359ac8c2ebc8e483d2f82672;p=inkscape.git diff --git a/buildtool.cpp b/buildtool.cpp index da482971b..bc6da92d3 100644 --- a/buildtool.cpp +++ b/buildtool.cpp @@ -4059,6 +4059,8 @@ bool MakeBase::executeCommand(const String &command, #include + + /** * Execute a system call, using pipes to send data to the * program's stdin, and reading stdout and stderr. @@ -4119,28 +4121,52 @@ bool MakeBase::executeCommand(const String &command, String outb; String errb; - FILE *stdOutRead = fdopen(outfds[0], "r"); - while (!feof(stdOutRead)) - { - char ch = fgetc(stdOutRead); - if (ch<0) - break; - outb.push_back(ch); - } - FILE *stdErrRead = fdopen(errfds[0], "r"); - while (!feof(stdErrRead)) + int outRead = outfds[0]; + int errRead = errfds[0]; + int max = outRead; + if (errRead > max) + max = errRead; + + bool outOpen = true; + bool errOpen = true; + + while (outOpen || errOpen) { - char ch = fgetc(stdErrRead); - if (ch<0) + char ch; + fd_set fdset; + FD_ZERO(&fdset); + if (outOpen) + FD_SET(outRead, &fdset); + if (errOpen) + FD_SET(errRead, &fdset); + int ret = select(max+1, &fdset, NULL, NULL, NULL); + if (ret < 0) break; - errb.push_back(ch); + if (FD_ISSET(outRead, &fdset)) + { + if (read(outRead, &ch, 1) <= 0) + outOpen = false; + else if (ch <= 0) + outOpen = false; + else + outb.push_back(ch); + } + if (FD_ISSET(errRead, &fdset)) + { + if (read(errRead, &ch, 1) <= 0) + errOpen = false; + else if (ch <= 0) + errOpen = false; + else + errb.push_back(ch); + } } int childReturnValue; wait(&childReturnValue); - fclose(stdOutRead); - fclose(stdErrRead); + close(outRead); + close(errRead); outbuf = outb; errbuf = errb;