aboutsummaryrefslogtreecommitdiff
path: root/src/core/memory.cpp
diff options
context:
space:
mode:
authorwwylele <wwylele@gmail.com>2016-06-27 20:42:42 +0300
committerwwylele <wwylele@gmail.com>2016-08-27 21:38:06 +0800
commit3008911345f3c5bed0976d6a787ebf1419a8fa6a (patch)
tree90327dc0e58493de455fa4a4fdd4599ee8c6477a /src/core/memory.cpp
parent9864343e0e855511b5f33c3e03c5a9984d2ceefc (diff)
Memory: add ReadCString function
Diffstat (limited to 'src/core/memory.cpp')
-rw-r--r--src/core/memory.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index 8c9e5d46dd..9aa8c4e5af 100644
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -280,6 +280,20 @@ u8* GetPointer(const VAddr vaddr) {
return nullptr;
}
+std::string ReadCString(VAddr vaddr, std::size_t max_length) {
+ std::string string;
+ string.reserve(max_length);
+ for (std::size_t i = 0; i < max_length; ++i) {
+ char c = Read8(vaddr);
+ if (c == '\0')
+ break;
+ string.push_back(c);
+ ++vaddr;
+ }
+ string.shrink_to_fit();
+ return string;
+}
+
u8* GetPhysicalPointer(PAddr address) {
// TODO(Subv): This call should not go through the application's memory mapping.
return GetPointer(PhysicalToVirtualAddress(address));