OSDN Git Service

The short_format var isnt used in flthdr.c, so delete it
[uclinux-h8/elf2flt.git] / flthdr.c
index 8635462..15301f5 100644 (file)
--- a/flthdr.c
+++ b/flthdr.c
 #include <string.h>   /* strcat(), strcpy() */
 
 /* 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
 
 /* from uClinux-x.x.x/include/linux */
 #include "flat.h"     /* Binary flat header description                      */
 
+#if defined(__MINGW32__)
+#include <getopt.h>
+
+#define mkstemp(p) mktemp(p)
+
+#endif
+
 /****************************************************************************/
 
 char *program_name;
 
 static char cmd[1024];
 static int print = 0, compress = 0, ramload = 0, stacksize = 0, ktrace = 0;
-static int short_format = 0;
 
 /****************************************************************************/
 
@@ -72,7 +84,7 @@ process_file(char *ifile, char *ofile)
 
        *tfile = *tfile2 = '\0';
 
-       if ((ifp = fopen(ifile, "rb")) == NULL) {
+       if ((ifp = fopen(ifile, "r" BINARY_FILE_OPTS)) == NULL) {
                fprintf(stderr, "Cannot open %s\n", ifile);
                return;
        }
@@ -195,7 +207,7 @@ process_file(char *ifile, char *ofile)
 
        strcpy(tfile, "/tmp/flatXXXXXX");
        mkstemp(tfile);
-       if ((ofp = fopen(tfile, "wb")) == NULL) {
+       if ((ofp = fopen(tfile, "w" BINARY_FILE_OPTS)) == NULL) {
                fprintf(stderr, "Failed to open %s for writing\n", tfile);
                unlink(tfile);
                unlink(tfile2);
@@ -220,7 +232,7 @@ process_file(char *ifile, char *ofile)
                mkstemp(tfile2);
                
                if (old_flags & FLAT_FLAG_GZDATA) {
-                       tfp = fopen(tfile2, "wb");
+                       tfp = fopen(tfile2, "w" BINARY_FILE_OPTS);
                        if (!tfp) {
                                fprintf(stderr, "Failed to open %s for writing\n", tfile2);
                                exit(1);
@@ -231,7 +243,7 @@ process_file(char *ifile, char *ofile)
                }
 
                sprintf(cmd, "gunzip >> %s", tfile2);
-               tfp = popen(cmd, "wb");
+               tfp = popen(cmd, "w" BINARY_FILE_OPTS);
                if(!tfp) {
                        perror("popen");
                        exit(1);
@@ -240,7 +252,7 @@ process_file(char *ifile, char *ofile)
                pclose(tfp);
 
                fclose(ifp);
-               ifp = fopen(tfile2, "rb");
+               ifp = fopen(tfile2, "r" BINARY_FILE_OPTS);
                if (!ifp) {
                        fprintf(stderr, "Failed to open %s for reading\n", tfile2);
                        unlink(tfile);
@@ -253,7 +265,7 @@ process_file(char *ifile, char *ofile)
                printf("zflat %s --> %s\n", ifile, ofile);
                fclose(ofp);
                sprintf(cmd, "gzip -9 -f >> %s", tfile);
-               ofp = popen(cmd, "wb");
+               ofp = popen(cmd, "w" BINARY_FILE_OPTS);
                ofp_is_pipe = 1;
        } else if (new_flags & FLAT_FLAG_GZDATA) {
                printf("zflat-data %s --> %s\n", ifile, ofile);
@@ -261,7 +273,7 @@ process_file(char *ifile, char *ofile)
                                sizeof(struct flat_hdr));
                fclose(ofp);
                sprintf(cmd, "gzip -9 -f >> %s", tfile);
-               ofp = popen(cmd, "wb");
+               ofp = popen(cmd, "w" BINARY_FILE_OPTS);
                ofp_is_pipe = 1;
        }