Unified · Split
| @@ -2423,11 +2423,10 @@ static int tcc_write_elf_file(TCCState *s1, const char *filename, int phnum, · 2422 unmodified lines | ||
| 2423 | 2423 | mode = 0777; |
| 2424 | 2424 | unlink(filename); |
| 2425 | 2425 | fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode); |
| 2426 | − if (fd < 0) { | |
| 2427 | − tcc_error_noabort("could not write '%s'", filename); | |
| 2426 | + if (fd < 0 || (f = fdopen(fd, "wb")) == NULL) { | |
| 2427 | + tcc_error_noabort("could not write or fdopen '%s'", filename); | |
| 2428 | 2428 | return -1; |
| 2429 | 2429 | } |
| 2430 | − f = fdopen(fd, "wb"); | |
| 2431 | 2430 | if (s1->verbose) |
| 2432 | 2431 | printf("<- %s\n", filename); |
| 2433 | 2432 | |
| @@ -795,11 +795,10 @@ ST_FUNC int macho_output_file(TCCState *s1, const char *filename) · 794 unmodified lines | ||
| 795 | 795 | mode = 0777; |
| 796 | 796 | unlink(filename); |
| 797 | 797 | fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode); |
| 798 | − if (fd < 0) { | |
| 798 | + if (fd < 0 || (fp = fdopen(fd, "wb")) == NULL) { | |
| 799 | 799 | tcc_error_noabort("could not write '%s: %s'", filename, strerror(errno)); |
| 800 | 800 | return -1; |
| 801 | 801 | } |
| 802 | − fp = fdopen(fd, "wb"); | |
| 803 | 802 | if (s1->verbose) |
| 804 | 803 | printf("<- %s\n", filename); |
| 805 | 804 | |