Skip to content

Instantly share code, notes, and snippets.

@Lazzlo2096
Last active April 9, 2018 12:47
Show Gist options
  • Save Lazzlo2096/b90b195525d7f0c701b3f9bf4a7800bb to your computer and use it in GitHub Desktop.
Save Lazzlo2096/b90b195525d7f0c701b3f9bf4a7800bb to your computer and use it in GitHub Desktop.
How compile fdupes on windows (but no!)
// https://github.com/libressl-portable/portable/blob/master/include/compat/sys/stat.h
// Dont forget place file "portable_endian.h" from https://gist.github.com/panzi/6856583 in /md5 directory
// This make fdupes compile, but it still dosen't work on windows (I think trouble in file API or something like)
// https://msdn.microsoft.com/en-us/library/14h5k7ff.aspx
// https://arrayfire.com/cross-compile-to-windows-from-linux/
diff --git a/Makefile b/Makefile
index bc5ff54..1cb3925 100644
--- a/Makefile
+++ b/Makefile
@@ -70,7 +70,7 @@ MKDIR = mkdir -p
#
# Make Configuration
#
-CC ?= gcc
+CC = x86_64-w64-mingw32-gcc
COMPILER_OPTIONS = -Wall -O -g
CFLAGS= $(COMPILER_OPTIONS) -I. -DVERSION=\"$(VERSION)\" $(OMIT_GETOPT_LONG) $(FILEOFFSET_64BIT)
@@ -92,8 +92,8 @@ OBJECT_FILES = fdupes.o md5/md5.o $(ADDITIONAL_OBJECTS)
all: fdupes
-fdupes: $(OBJECT_FILES)
- $(CC) $(CFLAGS) $(LDFLAGS) -o fdupes $(OBJECT_FILES)
+fdupes:
+ $(CC) $(CFLAGS) $(LDFLAGS) -o fdupes ./md5/md5.c ./fdupes.c
installdirs:
test -d $(DESTDIR)$(BIN_DIR) || $(MKDIR) $(DESTDIR)$(BIN_DIR)
diff --git a/fdupes.c b/fdupes.c
index 7a8a6ed..04d2fcd 100644
--- a/fdupes.c
+++ b/fdupes.c
@@ -22,8 +22,9 @@
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
-#include <sys/stat.h>
#include <dirent.h>
+#include <sys/stat.h>
+#include <windows.h>
#include <unistd.h>
#include <stdlib.h>
#ifndef OMIT_GETOPT_LONG
@@ -55,6 +56,9 @@
#define F_REVERSE 0x4000
#define F_IMMEDIATE 0x8000
+//#define S_IFLNK 0
+#define S_ISLNK(mode) (((mode) & _S_IFMT) == 0)
+
typedef enum {
ORDER_MTIME = 0,
ORDER_CTIME,
@@ -330,7 +334,7 @@ int grokdir(char *dir, file_t **filelistp)
continue;
}
- if (lstat(newfile->d_name, &linfo) == -1) {
+ if (_stat(newfile->d_name, &linfo) == -1) {
free(newfile->d_name);
free(newfile);
continue;
@@ -764,8 +768,8 @@ int relink(char *oldfile, char *newfile)
od = getdevice(oldfile);
oi = getinode(oldfile);
- if (link(oldfile, newfile) != 0)
- return 0;
+ //if (_link(oldfile, newfile) != 0)
+ // return 0;
/* make sure we're working with the right file (the one we created) */
nd = getdevice(newfile);
diff --git a/md5/md5.c b/md5/md5.c
index 3e8b694..f97a638 100644
--- a/md5/md5.c
+++ b/md5/md5.c
@@ -51,7 +51,7 @@
#ifdef __APPLE__
# include <machine/endian.h>
#else
-# include <endian.h>
+# include "portable_endian.h"
#endif
#if __BYTE_ORDER == __BIG_ENDIAN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment