Mercurial > hg > dmlib
comparison tools/objlink.c @ 2565:d56a0e86067a
Improve error handling.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 28 Feb 2022 11:49:58 +0200 |
parents | 2cf4e995b50c |
children | 9807ae37ad69 |
comparison
equal
deleted
inserted
replaced
2564:2cf4e995b50c | 2565:d56a0e86067a |
---|---|
574 | 574 |
575 // Open the input file | 575 // Open the input file |
576 if ((fh = fopen(filename, "rb")) == NULL) | 576 if ((fh = fopen(filename, "rb")) == NULL) |
577 { | 577 { |
578 res = dmGetErrno(); | 578 res = dmGetErrno(); |
579 dmErrorMsg("Error opening input file '%s' #%d: %s.\n", | 579 dmErrorMsg("Error opening input file '%s': %s.\n", |
580 filename, res, dmErrorStr(res)); | 580 filename, dmErrorStr(res)); |
581 goto out; | 581 goto out; |
582 } | 582 } |
583 | 583 |
584 // Get filesize | 584 // Get filesize |
585 if ((dataSize = dmGetFileSize(fh) - 2) < 0) | 585 if ((dataSize = dmGetFileSize(fh) - 2) < 0) |
586 { | 586 { |
587 res = dmGetErrno(); | 587 res = dmGetErrno(); |
588 dmErrorMsg("Error getting file size for '%s' #%d: %s.\n", | 588 dmErrorMsg("Error getting file size for '%s': %s.\n", |
589 filename, res, dmErrorStr(res)); | 589 filename, dmErrorStr(res)); |
590 goto out; | 590 goto out; |
591 } | 591 } |
592 | 592 |
593 // Get loading address | 593 // Get loading address |
594 if (!dm_fread_le16(fh, &tmpAddr)) | 594 if (!dm_fread_le16(fh, &tmpAddr)) |
595 { | 595 { |
596 res = dmGetErrno(); | 596 res = dmGetErrno(); |
597 dmErrorMsg("Error reading input file '%s' #%d: %s.\n", | 597 dmErrorMsg("Error reading input file '%s': %s.\n", |
598 filename, res, dmErrorStr(res)); | 598 filename, dmErrorStr(res)); |
599 goto out; | 599 goto out; |
600 } | 600 } |
601 | 601 |
602 // Show information | 602 // Show information |
603 loadAddr = forceAddr ? destAddr : tmpAddr; | 603 loadAddr = forceAddr ? destAddr : tmpAddr; |
615 | 615 |
616 // Load data | 616 // Load data |
617 if (fread(&memory[loadAddr], dataSize, 1, fh) < 1) | 617 if (fread(&memory[loadAddr], dataSize, 1, fh) < 1) |
618 { | 618 { |
619 res = dmGetErrno(); | 619 res = dmGetErrno(); |
620 dmPrint(1, " .. Error #%d: %s.\n", | 620 dmPrint(1, " .. Error: %s.\n", |
621 res, dmErrorStr(res)); | 621 dmErrorStr(res)); |
622 goto out; | 622 goto out; |
623 } | 623 } |
624 | 624 |
625 dmPrint(1, " .. OK\n"); | 625 dmPrint(1, " .. OK\n"); |
626 | 626 |
643 | 643 |
644 // Open the input file | 644 // Open the input file |
645 if ((fh = fopen(filename, "rb")) == NULL) | 645 if ((fh = fopen(filename, "rb")) == NULL) |
646 { | 646 { |
647 res = dmGetErrno(); | 647 res = dmGetErrno(); |
648 dmErrorMsg("Error opening input file '%s' #%d: %s.\n", | 648 dmErrorMsg("Error opening input file '%s': %s.\n", |
649 filename, res, dmErrorStr(res)); | 649 filename, dmErrorStr(res)); |
650 goto out; | 650 goto out; |
651 } | 651 } |
652 | 652 |
653 // Get filesize | 653 // Get filesize |
654 if ((dataSize = dmGetFileSize(fh)) < 0) | 654 if ((dataSize = dmGetFileSize(fh)) < 0) |
672 | 672 |
673 // Load data | 673 // Load data |
674 if (fread(&memory[destAddr], dataSize, 1, fh) < 1) | 674 if (fread(&memory[destAddr], dataSize, 1, fh) < 1) |
675 { | 675 { |
676 res = dmGetErrno(); | 676 res = dmGetErrno(); |
677 dmPrint(1, " .. Error reading data #%d: %s.\n", | 677 dmPrint(1, " .. Error reading data: %s.\n", |
678 res, dmErrorStr(res)); | 678 dmErrorStr(res)); |
679 goto out; | 679 goto out; |
680 } | 680 } |
681 | 681 |
682 dmPrint(1, " .. OK\n"); | 682 dmPrint(1, " .. OK\n"); |
683 | 683 |
853 argHandleOpt, NULL, OPTH_BAILOUT)) | 853 argHandleOpt, NULL, OPTH_BAILOUT)) |
854 goto out; | 854 goto out; |
855 | 855 |
856 if (nsrcFiles < 1) | 856 if (nsrcFiles < 1) |
857 { | 857 { |
858 dmErrorMsg("Nothing to do. (try --help)\n"); | 858 argShowHelp(); |
859 res = dmError(DMERR_INVALID_ARGS, | |
860 "No input file(s) specified.\n"); | |
859 goto out; | 861 goto out; |
860 } | 862 } |
861 | 863 |
862 // Warn about overlaps if enabled | 864 // Warn about overlaps if enabled |
863 if (optAllowOverlap) | 865 if (optAllowOverlap) |