hessu / bchunk

BinChunker for Unix / Linux converts .bin / .cue images to .iso and .cdr
GNU General Public License v2.0
63 stars 15 forks source link

MinGW compatibility #3

Closed amroamroamro closed 6 years ago

amroamroamro commented 6 years ago

Here is a patch that enables building on Windows using MinGW-w64:

Now we can compiled using:

$ LDFLAGS=-lws2_32 mingw32-make

mingw.patch

From dbcd352870313684e27d97a682867832a4f9b69a Mon Sep 17 00:00:00 2001
From: Amro <amroamroamro@gmail.com>
Date: Mon, 19 Mar 2018 17:35:29 +0200
Subject: [PATCH] MinGW compatibility

can now be compiled in mingw-w64 as:
$ LDFLAGS=-lws2_32 mingw32-make
---
 Makefile | 2 +-
 bchunk.c | 8 ++++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 17942c3..1124a21 100644
--- a/Makefile
+++ b/Makefile
@@ -33,7 +33,7 @@ installman:
 BITS = bchunk.o

 bchunk: $(BITS)
-   $(LD) $(LDFLAGS) -o bchunk $(BITS)
+   $(LD) -o bchunk $(BITS) $(LDFLAGS)

 bchunk.o:  bchunk.c

diff --git a/bchunk.c b/bchunk.c
index 686f2be..52f1aa9 100644
--- a/bchunk.c
+++ b/bchunk.c
@@ -59,7 +59,11 @@
  */

 #include <inttypes.h>
+#ifdef _WIN32
+#include <winsock2.h>
+#else
 #include <netinet/in.h>
+#endif

 #define bswap_16(x) \
      ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
@@ -279,7 +283,7 @@ int writetrack(FILE *bf, struct track_t *track, char *bname)

    printf("%2d: %s ", track->num, fname);

-   if (!(f = fopen(fname, "w"))) {
+   if (!(f = fopen(fname, "wb"))) {
        fprintf(stderr, " Could not fopen track file: %s\n", strerror(errno));
        exit(4);
    }
@@ -398,7 +402,7 @@ int main(int argc, char **argv)

    parse_args(argc, argv);

-   if (!((binf = fopen(binfile, "r")))) {
+   if (!((binf = fopen(binfile, "rb")))) {
        fprintf(stderr, "Could not open BIN %s: %s\n", binfile, strerror(errno));
        return 2;
    }
-- 
2.15.1
hessu commented 6 years ago

Thank you, nice clean patch, applied!