#include <inttypes.h>
#include <assert.h>
-/* macros for conversion between host and (internet) network byte order */
-#ifndef WIN32
-#include <netinet/in.h> /* Consts and structs defined by the internet system */
-#define BINARY_FILE_OPTS
-#else
-#include <winsock2.h>
-#define BINARY_FILE_OPTS "b"
-#endif
-
#include "compress.h"
#include <libiberty.h>
+#include "stubs.h"
+const char *elf2flt_progname;
+
/* from uClinux-x.x.x/include/linux */
#include "flat.h" /* Binary flat header description */
/****************************************************************************/
-char *program_name;
-
static int print = 0, print_relocs = 0, docompress = 0, ramload = 0,
stacksize = 0, ktrace = 0, l1stack = 0;
tfile = make_temp_file("flthdr");
if (fopen_stream_u(&ofp, tfile, "w" BINARY_FILE_OPTS)) {
- fprintf(stderr, "Failed to open %s for writing\n", tfile);
unlink(tfile);
- exit(1);
+ fatal("Failed to open %s for writing\n", tfile);
}
/* Copy header (always uncompressed). */
if (fwrite_stream(&new_hdr, sizeof(new_hdr), 1, &ofp) != 1) {
- fprintf(stderr, "Failed to write to %s\n", tfile);
unlink(tfile);
- exit(1);
+ fatal("Failed to write to %s\n", tfile);
}
/* Whole input file (including text) is compressed: start decompressing
output_error = ferror_stream(&ofp);
if (input_error || output_error) {
- fprintf(stderr, "Error on file pointer%s%s\n",
+ unlink(tfile);
+ fatal("Error on file pointer%s%s\n",
input_error ? " input" : "",
output_error ? " output" : "");
- unlink(tfile);
- exit(1);
}
fclose_stream(&ifp);
{
if (s)
fprintf(stderr, "%s\n", s);
- fprintf(stderr, "usage: %s [options] flat-file\n", program_name);
+ fprintf(stderr, "usage: %s [options] flat-file\n", elf2flt_progname);
fprintf(stderr, " Allows you to change an existing flat file\n\n");
fprintf(stderr, " -p : print current settings\n");
fprintf(stderr, " -P : print relocations\n");
int
main(int argc, char *argv[])
{
- int c;
+ int c, noargs;
char *ofile = NULL, *ifile;
- program_name = argv[0];
+ elf2flt_progname = argv[0];
+ noargs = 1;
while ((c = getopt(argc, argv, "pPdzZrRuUkKs:o:")) != EOF) {
switch (c) {
case 'p': print = 1; break;
usage("invalid option");
break;
}
+ noargs = 0;
}
if (optind >= argc)
if (ofile && argc - optind > 1)
usage("-o can only be used with a single file");
- if (!print && !docompress && !ramload && !stacksize) /* no args == print */
+ if (!print && noargs) /* no args == print */
print = argc - optind; /* greater than 1 is short format */
-
+
for (c = optind; c < argc; c++) {
ifile = argv[c];
if (!ofile)