| 245 | //------------------------------------------------------------------------- |
| 246 | |
| 247 | RecMessage * |
| 248 | RecMessageReadFromDisk(const char *fpath) |
| 249 | { |
| 250 | RecMessageHdr msg_hdr; |
| 251 | RecMessage *msg = nullptr; |
| 252 | RecHandle h_file; |
| 253 | int bytes_read; |
| 254 | |
| 255 | if ((h_file = RecFileOpenR(fpath)) == REC_HANDLE_INVALID) { |
| 256 | goto Lerror; |
| 257 | } |
| 258 | if (RecFileRead(h_file, reinterpret_cast<char *>(&msg_hdr), sizeof(RecMessageHdr), &bytes_read) == REC_ERR_FAIL) { |
| 259 | goto Lerror; |
| 260 | } |
| 261 | msg = static_cast<RecMessage *>(ats_malloc((msg_hdr.o_end - msg_hdr.o_start) + sizeof(RecMessageHdr))); |
| 262 | memcpy(msg, &msg_hdr, sizeof(RecMessageHdr)); |
| 263 | if (RecSnapFileRead(h_file, reinterpret_cast<char *>(msg) + msg_hdr.o_start, msg_hdr.o_end - msg_hdr.o_start, &bytes_read) == |
| 264 | REC_ERR_FAIL) { |
| 265 | goto Lerror; |
| 266 | } |
| 267 | |
| 268 | goto Ldone; |
| 269 | |
| 270 | Lerror: |
| 271 | ats_free(msg); |
| 272 | msg = nullptr; |
| 273 | |
| 274 | Ldone: |
| 275 | if (h_file != REC_HANDLE_INVALID) { |
| 276 | RecFileClose(h_file); |
| 277 | } |
| 278 | |
| 279 | return msg; |
| 280 | } |
| 281 | |
| 282 | //------------------------------------------------------------------------- |
| 283 | // RecMessageWriteToDisk |
no test coverage detected