1 /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
2 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
3 /* Updated 2008 to use fread/fopen and friends instead of read/open so it compiles with GCC on Unix (Rubidium) */
16 unsigned short header
[3];
21 char *dot
= strrchr(fname
, '.');
22 if (!dot
|| strlen(dot
) != 4
23 || tolower(dot
[1]) != 'e'
24 || tolower(dot
[2]) != 'x'
25 || tolower(dot
[3]) != 'e')
27 fprintf(stderr
, "%s: Arguments MUST end with a .exe extension\n", fname
);
31 ifile
= fopen(fname
, "rb");
37 fread(header
, sizeof(header
), 1, ifile
);
38 if (header
[0] == 0x5a4d)
40 long header_offset
= (long)header
[2]*512L;
42 header_offset
+= (long)header
[1] - 512L;
43 fseek(ifile
, header_offset
, SEEK_SET
);
45 fread(header
, sizeof(header
), 1, ifile
);
46 if ((header
[0] != 0x010b) && (header
[0] != 0x014c))
48 fprintf(stderr
, "`%s' does not have a COFF/AOUT program appended to it\n", fname
);
51 fseek(ifile
, header_offset
, SEEK_SET
);
55 fprintf(stderr
, "`%s' is not an .EXE file\n", fname
);
60 ofile
= fopen(fname
, "w+b");
67 while ((rbytes
=fread(buf
, 1, 4096, ifile
)) > 0)
69 int wb
= fwrite(buf
, 1, rbytes
, ofile
);
77 fprintf(stderr
, "`%s': disk full\n", fname
);
86 main(int argc
, char **argv
)
89 if (argc
== 1) printf("Usage: %s <exename>", argv
[0]);
90 for (i
=1; i
<argc
; i
++)