| 7 | namespace Host { |
| 8 | |
| 9 | Expect<const char *> read_c_str(Runtime::Instance::MemoryInstance *memory, |
| 10 | uint32_t ptr) { |
| 11 | uint32_t tail = ptr; |
| 12 | while (true) { |
| 13 | auto ch = memory->getBytes(tail, 1); |
| 14 | if (!ch.has_value()) |
| 15 | return Unexpect(ch.error()); |
| 16 | if (ch.value()[0] == '\0') |
| 17 | break; |
| 18 | tail++; |
| 19 | } |
| 20 | uint32_t len = tail - ptr + 1; |
| 21 | return memory->getSpan<const char>(ptr, len).data(); |
| 22 | } |
| 23 | |
| 24 | } // namespace Host |
| 25 | } // namespace WasmEdge |