| 450 | } |
| 451 | |
| 452 | txLinkerScript* fxNewLinkerScript(txLinker* linker, txString path, FILE** fileAddress) |
| 453 | { |
| 454 | txLinkerScript* script = NULL; |
| 455 | FILE* aFile = NULL; |
| 456 | Atom atom; |
| 457 | txByte version[4]; |
| 458 | script = fxNewLinkerChunkClear(linker, sizeof(txLinkerScript)); |
| 459 | script->path = fxNewLinkerString(linker, path, mxStringLength(path)); |
| 460 | aFile = fopen(path, "rb"); |
| 461 | mxThrowElse(aFile); |
| 462 | *fileAddress = aFile; |
| 463 | mxThrowElse(fread(&atom, sizeof(atom), 1, aFile) == 1); |
| 464 | atom.atomSize = ntohl(atom.atomSize); |
| 465 | atom.atomType = ntohl(atom.atomType); |
| 466 | mxAssert(atom.atomType == XS_ATOM_BINARY); |
| 467 | |
| 468 | mxThrowElse(fread(&atom, sizeof(atom), 1, aFile) == 1); |
| 469 | atom.atomSize = ntohl(atom.atomSize); |
| 470 | atom.atomType = ntohl(atom.atomType); |
| 471 | mxAssert(atom.atomType == XS_ATOM_VERSION); |
| 472 | mxThrowElse(fread(version, sizeof(version), 1, aFile) == 1); |
| 473 | mxAssert(version[0] == XS_MAJOR_VERSION); |
| 474 | mxAssert(version[1] == XS_MINOR_VERSION); |
| 475 | mxAssert(version[3] != 1); |
| 476 | |
| 477 | mxThrowElse(fread(&atom, sizeof(atom), 1, aFile) == 1); |
| 478 | atom.atomSize = ntohl(atom.atomSize); |
| 479 | atom.atomType = ntohl(atom.atomType); |
| 480 | mxAssert(atom.atomType == XS_ATOM_SYMBOLS); |
| 481 | script->symbolsSize = atom.atomSize - sizeof(atom); |
| 482 | script->symbolsBuffer = fxNewLinkerChunk(linker, script->symbolsSize); |
| 483 | mxThrowElse(fread(script->symbolsBuffer, script->symbolsSize, 1, aFile) == 1); |
| 484 | |
| 485 | mxThrowElse(fread(&atom, sizeof(atom), 1, aFile) == 1); |
| 486 | atom.atomSize = ntohl(atom.atomSize); |
| 487 | atom.atomType = ntohl(atom.atomType); |
| 488 | mxAssert(atom.atomType == XS_ATOM_CODE); |
| 489 | script->codeSize = atom.atomSize - sizeof(atom); |
| 490 | script->codeBuffer = fxNewLinkerChunk(linker, script->codeSize); |
| 491 | mxThrowElse(fread(script->codeBuffer, script->codeSize, 1, aFile) == 1); |
| 492 | |
| 493 | if (version[3] == -1) { |
| 494 | mxThrowElse(fread(&atom, sizeof(atom), 1, aFile) == 1); |
| 495 | atom.atomSize = ntohl(atom.atomSize); |
| 496 | atom.atomType = ntohl(atom.atomType); |
| 497 | mxAssert(atom.atomType == XS_ATOM_HOSTS); |
| 498 | script->hostsSize = atom.atomSize - sizeof(atom); |
| 499 | script->hostsBuffer = fxNewLinkerChunk(linker, script->hostsSize); |
| 500 | mxThrowElse(fread(script->hostsBuffer, script->hostsSize, 1, aFile) == 1); |
| 501 | } |
| 502 | |
| 503 | fclose(aFile); |
| 504 | *fileAddress = NULL; |
| 505 | return script; |
| 506 | } |
| 507 | |
| 508 | txString fxNewLinkerString(txLinker* linker, txString buffer, txSize size) |
| 509 | { |
no test coverage detected