Date: Sun, 16 Aug 1998 12:56:04 +0300 (IDT) From: Eli Zaretskii To: DJ Delorie cc: djgpp-workers AT delorie DOT com Subject: exe2coff and files withg no .exe extension Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk I am told that exe2coff does bad things when invoked with stubified files that lack the .exe suffix. I think such files are generally a bad idea (for starters, DOS won't run them), but here's a stopgap that will at least prevent exe2coff from crashing: *** src/stub/exe2coff.c~0 Thu Jan 1 20:38:50 1998 --- src/stub/exe2coff.c Fri Aug 14 13:02:32 1998 *************** *** 7,12 **** --- 7,13 ---- #include #include #include + #include static void *************** exe2aout(char *fname) *** 17,22 **** --- 18,33 ---- int ofile; char buf[4096]; int rbytes; + char *dot = strrchr(fname, '.'); + if (!dot || strlen(dot) != 4 + || tolower(dot[1]) != 'e' + || tolower(dot[2]) != 'x' + || tolower(dot[3]) != 'e') + { + fprintf(stderr, "Arguments MUST end with a .exe extension\n", fname); + return; + } + ifile = open(fname, O_RDONLY|O_BINARY); if (ifile < 0) { *************** exe2aout(char *fname) *** 34,51 **** read(ifile, header, sizeof(header)); if ((header[0] != 0x010b) && (header[0] != 0x014c)) { ! fprintf(stderr, "%s does not have an a.out file appended to it\n", fname); ! exit(1); } lseek(ifile, header_offset, 0); } else { ! fprintf(stderr, "%s is not an .EXE file\n", fname); ! exit(1); } ! *strrchr(fname, '.') = 0; ofile = open(fname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0666); if (ofile < 0) { --- 45,62 ---- read(ifile, header, sizeof(header)); if ((header[0] != 0x010b) && (header[0] != 0x014c)) { ! fprintf(stderr, "`%s' does not have a COFF/AOUT program appended to it\n", fname); ! return; } lseek(ifile, header_offset, 0); } else { ! fprintf(stderr, "`%s' is not an .EXE file\n", fname); ! return; } ! *dot = 0; ofile = open(fname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0666); if (ofile < 0) { *************** exe2aout(char *fname) *** 63,69 **** } if (wb < rbytes) { ! fprintf(stderr, "%s: disk full\n", fname); exit(1); } } --- 74,80 ---- } if (wb < rbytes) { ! fprintf(stderr, "`%s': disk full\n", fname); exit(1); } }