summaryrefslogtreecommitdiff
path: root/src/mem/port_proxy.cc
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2019-05-01 21:41:36 -0700
committerGabe Black <gabeblack@google.com>2019-05-29 04:24:11 +0000
commite2e26d3dc9fcf6015f73659a66c4c8fb4f2ec691 (patch)
tree68b5be6382612c5bf13e2b1f1e7fbd686771e723 /src/mem/port_proxy.cc
parent1a631bd79bdcf2d66d845f79758e16e3ec9d7a7f (diff)
downloadgem5-e2e26d3dc9fcf6015f73659a66c4c8fb4f2ec691.tar.xz
mem: Add a readString method to the PortProxy which takes a char *.
This version takes a char * instead of an std::string &, and a maximum length to fill in like strncpy. This is intended to be a replacement for the CopyStringOut function. Change-Id: Ib661924a3fa7e05761d572ffecbe2c0cc8659d48 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/18574 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Jason Lowe-Power <jason@lowepower.com> Reviewed-by: Brandon Potter <Brandon.Potter@amd.com> Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com> Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
Diffstat (limited to 'src/mem/port_proxy.cc')
-rw-r--r--src/mem/port_proxy.cc15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/mem/port_proxy.cc b/src/mem/port_proxy.cc
index f56bfeb55..60f79e375 100644
--- a/src/mem/port_proxy.cc
+++ b/src/mem/port_proxy.cc
@@ -110,3 +110,18 @@ PortProxy::tryReadString(std::string &str, Addr addr) const
str += c;
}
}
+
+bool
+PortProxy::tryReadString(char *str, Addr addr, size_t maxlen) const
+{
+ assert(maxlen);
+ while (maxlen--) {
+ if (!tryReadBlob(addr++, str, 1))
+ return false;
+ if (!*str++)
+ return true;
+ }
+ // We ran out of room, so back up and add a terminator.
+ *--str = '\0';
+ return true;
+}