summaryrefslogtreecommitdiff
path: root/proc-region-rw.c
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2018-10-18 16:06:56 +0300
committerJari Vetoniemi <mailroxas@gmail.com>2018-10-18 16:06:56 +0300
commitfcadd18b07e55f4a6d21f9f378de9ded25be7e67 (patch)
treeab6ab78fb3150da27b099860bdf5a0eae062034d /proc-region-rw.c
parent82eb10b0c7ae9382a4bbc97071c74de9055ad56e (diff)
fix read mode
Diffstat (limited to 'proc-region-rw.c')
-rw-r--r--proc-region-rw.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/proc-region-rw.c b/proc-region-rw.c
index c2a9b13..a7ad2ca 100644
--- a/proc-region-rw.c
+++ b/proc-region-rw.c
@@ -78,13 +78,15 @@ context_init(struct context *ctx, size_t argc, const char *argv[])
ctx->op.has_len = true;
}
- if (wmname && !(ctx->op.wm.src = fopen(wmname, "rb")))
- err(EXIT_FAILURE, "fopen(%s)", wmname);
+ if (wmname) {
+ if (!(ctx->op.wm.src = fopen(wmname, "rb")))
+ err(EXIT_FAILURE, "fopen(%s)", wmname);
- if (fseek(ctx->op.wm.src, 0, SEEK_END) != 0)
- err(EXIT_FAILURE, "fseek");
+ if (fseek(ctx->op.wm.src, 0, SEEK_END) != 0)
+ err(EXIT_FAILURE, "fseek");
- ctx->op.wm.size = ftell(ctx->op.wm.src);
+ ctx->op.wm.size = ftell(ctx->op.wm.src);
+ }
char path[128];
snprintf(path, sizeof(path), "/proc/%u/mem", ctx->proc.pid);
@@ -142,8 +144,12 @@ region_cb(const char *line, void *data)
}
region_offset = (ctx->op.mode == MODE_MAP ? region_offset : 0);
- const size_t rlen = (ctx->op.has_len ? ctx->op.len : ctx->op.wm.size); // requested write/read
- const size_t len = (rlen > end - start ? end - start : rlen); // actual write/read
+
+ // requested write/read
+ const size_t rlen = (ctx->op.has_len ? ctx->op.len : (ctx->op.mode == MODE_READ ? end - start : ctx->op.wm.size));
+
+ // actual write/read
+ const size_t len = (rlen > end - start ? end - start : rlen);
if (!len)
return;