Helper function to read file into a buffer.
| 440 | |
| 441 | // Helper function to read file into a buffer. |
| 442 | bool readToVector(const char *Path, std::vector<uint8_t> &Buf) { |
| 443 | std::ifstream F(Path, std::ios::binary | std::ios::ate); |
| 444 | if (!F) { |
| 445 | return false; |
| 446 | } |
| 447 | F.seekg(0, std::ios::end); |
| 448 | Buf.resize(static_cast<uint32_t>(F.tellg())); |
| 449 | F.seekg(0, std::ios::beg); |
| 450 | if (!F.read(reinterpret_cast<char *>(Buf.data()), |
| 451 | static_cast<uint32_t>(Buf.size()))) { |
| 452 | return false; |
| 453 | } |
| 454 | F.close(); |
| 455 | return true; |
| 456 | } |
| 457 | |
| 458 | // Helper function to check error code. |
| 459 | bool isErrMatch(WasmEdge_ErrCode Err, WasmEdge_Result Res) { |