diff options
author | Michael Neuling <mikey@neuling.org> | 2018-07-03 16:58:07 +1000 |
---|---|---|
committer | Alistair Popple <alistair@popple.id.au> | 2018-07-12 13:30:27 +1000 |
commit | 436eb8c74fb4a762b61837ee27ddbd6b5fe21334 (patch) | |
tree | 1f89e2c41c02a3de3230db9d7624b1e56bbfdae6 /libpdbg | |
parent | 5fc31fcd40cc3c56325f35c2cfabd754857205c7 (diff) | |
download | pdbg-436eb8c74fb4a762b61837ee27ddbd6b5fe21334.tar.gz pdbg-436eb8c74fb4a762b61837ee27ddbd6b5fe21334.zip |
htm: Use splice() to copy dump
Gives 10% speedup for no more complexity.
Signed-off-by: Michael Neuling <mikey@neuling.org>
Diffstat (limited to 'libpdbg')
-rw-r--r-- | libpdbg/htm.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/libpdbg/htm.c b/libpdbg/htm.c index fa15f5f..a494493 100644 --- a/libpdbg/htm.c +++ b/libpdbg/htm.c @@ -952,41 +952,39 @@ static int do_htm_status(struct htm *htm) return 1; } -#define COPY_BUF_SIZE getpagesize() static int copy_file(int output, int input, uint64_t size) { - char *buf; size_t r; + int pipefd[2]; + int rc = -1; - buf = malloc(COPY_BUF_SIZE); - if (!buf) { - PR_ERROR("Can't malloc buffer\n"); - return -1; + if (pipe(pipefd)) { + perror("pipe"); + exit(1); } while (size) { - r = read(input, buf, MIN(COPY_BUF_SIZE, size)); + r = splice(input, 0, pipefd[1], 0, size, 0); if (r == -1) { PR_ERROR("Failed to read\n"); goto out; } if (r == 0) { - PR_ERROR("EOF\n"); + PR_ERROR("Unexpect EOF\n"); goto out; } - if (write(output, buf, r) != r) { + if (splice(pipefd[0], 0, output, 0, r, 0) != r) { PR_ERROR("Short write!\n"); goto out; } size -= r; } - - return 0; - + rc = 0; out: - free(buf); - return -1; + close(pipefd[1]); + close(pipefd[0]); + return rc; } |