aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-11-04 16:31:25 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-11-04 16:31:43 +0000
commitc424dabb0d0a7c92bee82a1e62c07c8cef5d5f08 (patch)
tree2c47849d18eafffd5c92be3cc9755c7c95c0b0f4
parent6b8bbcfa904d3f5ddfa10d8f59d8099b0a428e77 (diff)
downloadpaludis-c424dabb0d0a7c92bee82a1e62c07c8cef5d5f08.tar.gz
paludis-c424dabb0d0a7c92bee82a1e62c07c8cef5d5f08.tar.xz
Use fewer syscalls
-rw-r--r--paludis/repositories/e/ebuild/utils/locked_pipe_command.cc24
1 files changed, 19 insertions, 5 deletions
diff --git a/paludis/repositories/e/ebuild/utils/locked_pipe_command.cc b/paludis/repositories/e/ebuild/utils/locked_pipe_command.cc
index ad71045..a2619f3 100644
--- a/paludis/repositories/e/ebuild/utils/locked_pipe_command.cc
+++ b/paludis/repositories/e/ebuild/utils/locked_pipe_command.cc
@@ -76,18 +76,32 @@ main(int argc, char *argv[])
}
/* copy write buffer to stdout until we get a null, and discard that null */
- while (((c = read(read_fd, buf, 1))) > 0)
+ while (((c = read(read_fd, buf, 1024))) > 0)
{
- if (buf[0] == '\0')
- break;
+ bool done(false);
+ if (buf[c - 1] == '\0')
+ {
+ done = true;
+ --c;
+ }
+
+ char * buf_p(buf);
+ while (((w = write(1, buf_p, c))) > 0)
+ {
+ c -= w;
+ buf_p += w;
+ if (c == 0)
+ break;
+ }
- while (((w = write(1, buf, c))) == 0)
- sleep(0);
if (w == -1)
{
std::cerr << "Error: " << argv[0] << ": write failed with " << ::strerror(errno) << std::endl;
return EXIT_FAILURE;
}
+
+ if (done)
+ break;
}
if (c == -1)