--- dpkg-1.14.23.orig/ostable
+++ dpkg-1.14.23/ostable
@@ -25,3 +25,4 @@
 bsd-netbsd	netbsd		netbsd[^-]*
 bsd-openbsd	openbsd		openbsd[^-]*
 sysv-solaris	solaris		solaris[^-]*
+gnu-interix	interix3	interix[^-]*
--- dpkg-1.14.23.orig/triplettable
+++ dpkg-1.14.23/triplettable
@@ -14,3 +14,4 @@
 bsd-netbsd-<cpu>	netbsd-<cpu>
 bsd-darwin-<cpu>	darwin-<cpu>
 sysv-solaris-<cpu>	solaris-<cpu>
+gnu-interix-<cpu>	interix-<cpu>
--- dpkg-1.14.23.orig/debian/changelog
+++ dpkg-1.14.23/debian/changelog
@@ -1,3 +1,24 @@
+dpkg (1.14.23-0+interix.3) unstable; urgency=low
+
+  * Non-maintainer upload.
+  * patches for interix-i386: remove versioned Conflicts on apt
+
+ -- Martin Koeppe <mkoeppe@gmx.de>  Tue, 09 Dec 2008 00:23:30 +0100
+
+dpkg (1.14.23-0+interix.2) unstable; urgency=low
+
+  * Non-maintainer upload.
+  * patches for interix-i386: correct file's GID
+
+ -- Martin Koeppe <mkoeppe@gmx.de>  Mon, 08 Dec 2008 01:29:37 +0100
+
+dpkg (1.14.23-0+interix.1) unstable; urgency=low
+
+  * Non-maintainer upload.
+  * patches for interix-i386
+
+ -- Martin Koeppe <mkoeppe@gmx.de>  Sun, 07 Dec 2008 20:44:56 +0100
+
 dpkg (1.14.23) unstable; urgency=low
 
   [ Raphael Hertzog ]
--- dpkg-1.14.23.orig/debian/control
+++ dpkg-1.14.23/debian/control
@@ -11,16 +11,15 @@
 Vcs-Git: git://git.debian.org/git/dpkg/dpkg.git
 Standards-Version: 3.7.3
 Build-Depends: debhelper (>= 4.1.81), pkg-config, po4a (>= 0.33.1),
- libncursesw5-dev, zlib1g-dev (>= 1:1.1.3-19.1), libbz2-dev, flex,
- libselinux1-dev (>= 1.28-4) [!hurd-i386 !kfreebsd-i386 !kfreebsd-amd64],
+ libncurses-dev, zlib1g-dev (>= 1:1.1.3-19.1), libbz2-dev, flex,
  libtimedate-perl, libio-string-perl
 
 Package: dpkg
 Architecture: any
 Essential: yes
-Pre-Depends: ${shlibs:Depends}, coreutils (>= 5.93-1), lzma
+Pre-Depends: ${shlibs:Depends}, lzma
 Conflicts: sysvinit (<< 2.82-1), dpkg-iasearch (<< 0.11),
- dpkg-dev (<< 1.14.16), apt (<< 0.7.7), aptitude (<< 0.4.7-1)
+ dpkg-dev (<< 1.14.16), aptitude (<< 0.4.7-1)
 Replaces: manpages-de (<= 0.4-3), manpages-pl (<= 20051117-1)
 Suggests: apt
 Description: Debian package management system
--- dpkg-1.14.23.orig/debian/dpkg.postinst
+++ dpkg-1.14.23/debian/dpkg.postinst
@@ -61,7 +61,7 @@
     logfile=/var/log/dpkg.log
     touch $logfile
     chmod 640 $logfile
-    chown root:adm $logfile 2>/dev/null || chown 0:4 $logfile
+    # chown root:adm $logfile 2>/dev/null || chown 0:4 $logfile
 }
 
 
--- dpkg-1.14.23.orig/debian/rules
+++ dpkg-1.14.23/debian/rules
@@ -33,6 +33,9 @@
 ifeq ($(DEB_HOST_ARCH_OS),linux)
 	confflags += --with-selinux=static
 endif
+ifeq ($(DEB_HOST_ARCH_OS),interix)
+	confflags += CPPFLAGS=-D_ALL_SOURCE
+endif
 
 
 # Create configure script if necessary, automake handles rebuilding it.
@@ -103,7 +106,7 @@
 	dh_compress -a
 	dh_fixperms -a
 	dh_installdeb -a
-	dh_shlibdeps -a
+	dh_shlibdeps -a -- -v
 	dh_gencontrol -a
 	dh_md5sums -a
 	dh_builddeb -a
--- dpkg-1.14.23.orig/debian/shlibs.default
+++ dpkg-1.14.23/debian/shlibs.default
@@ -5,3 +5,13 @@
 # dpkg-shlibdeps(1) manual page. 
 #
 # <library name>	<version/soname>	<dependencies>
+ld			1			ms-libc3.5
+libc			3.5			ms-libc3.5
+libdb			3.5			ms-libc3.5
+libdl			3.5			ms-libc3.5
+libm			3.5			ms-libc3.5
+libcurses		3.5			ms-libc3.5
+librpclib		3.5			ms-libc3.5
+#
+libstdc++		3.5			libstdc++3.5
+#
--- dpkg-1.14.23.orig/dpkg-deb/build.c
+++ dpkg-1.14.23/dpkg-deb/build.c
@@ -349,7 +349,7 @@
     m_dup2(p1[1],1); close(p1[0]); close(p1[1]);
     if (chdir(directory)) ohshite(_("failed to chdir to `%.255s'"),directory);
     if (chdir(BUILDCONTROLDIR)) ohshite(_("failed to chdir to .../DEBIAN"));
-    execlp(TAR, "tar", "-cf", "-", ".", NULL);
+    execlp(TAR, "tar", "-cf", "-", "--owner=0", "--group=0", ".", NULL);
     ohshite(_("failed to exec tar -cf"));
   }
   close(p1[1]);
@@ -422,7 +422,7 @@
     m_dup2(p1[0],0); close(p1[0]); close(p1[1]);
     m_dup2(p2[1],1); close(p2[0]); close(p2[1]);
     if (chdir(directory)) ohshite(_("failed to chdir to `%.255s'"),directory);
-    execlp(TAR, "tar", "-cf", "-", "--null", "-T", "-", "--no-recursion", NULL);
+    execlp(TAR, "tar", "-cf", "-", "--owner=0", "--group=0", "--null", "-T", "-", "--no-recursion", NULL);
     ohshite(_("failed to exec tar -cf"));
   }
   close(p1[0]);
--- dpkg-1.14.23.orig/dpkg-deb/Makefile.am
+++ dpkg-1.14.23/dpkg-deb/Makefile.am
@@ -17,5 +17,4 @@
 	main.c
 
 dpkg_deb_LDADD = \
-	../libcompat/libcompat.a \
-	$(LIBINTL) ../lib/libdpkg.a $(ZLIB_LIBS) $(BZ2_LIBS) $(SELINUX_LIBS)
+	$(LIBINTL) ../lib/libdpkg.a ../libcompat/libcompat.a $(ZLIB_LIBS) $(BZ2_LIBS) $(SELINUX_LIBS)
--- dpkg-1.14.23.orig/dpkg-deb/Makefile.in
+++ dpkg-1.14.23/dpkg-deb/Makefile.in
@@ -58,8 +58,8 @@
 	main.$(OBJEXT)
 dpkg_deb_OBJECTS = $(am_dpkg_deb_OBJECTS)
 am__DEPENDENCIES_1 =
-dpkg_deb_DEPENDENCIES = ../libcompat/libcompat.a $(am__DEPENDENCIES_1) \
-	../lib/libdpkg.a $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+dpkg_deb_DEPENDENCIES = ../lib/libdpkg.a $(am__DEPENDENCIES_1) \
+	../libcompat/libcompat.a $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
 	$(am__DEPENDENCIES_1)
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
 depcomp = $(SHELL) $(top_srcdir)/config/depcomp
@@ -213,8 +213,7 @@
 	main.c
 
 dpkg_deb_LDADD = \
-	../libcompat/libcompat.a \
-	$(LIBINTL) ../lib/libdpkg.a $(ZLIB_LIBS) $(BZ2_LIBS) $(SELINUX_LIBS)
+	$(LIBINTL) ../lib/libdpkg.a ../libcompat/libcompat.a $(ZLIB_LIBS) $(BZ2_LIBS) $(SELINUX_LIBS)
 
 all: all-am
 
--- dpkg-1.14.23.orig/dpkg-split/Makefile.am
+++ dpkg-1.14.23/dpkg-split/Makefile.am
@@ -19,9 +19,9 @@
 	split.c
 
 dpkg_split_LDADD = \
-	../libcompat/libcompat.a \
 	$(LIBINTL) \
-	../lib/libdpkg.a
+	../lib/libdpkg.a \
+	../libcompat/libcompat.a
 
 
 pkglib_SCRIPTS = mksplit
--- dpkg-1.14.23.orig/dpkg-split/Makefile.in
+++ dpkg-1.14.23/dpkg-split/Makefile.in
@@ -59,8 +59,8 @@
 	queue.$(OBJEXT) split.$(OBJEXT)
 dpkg_split_OBJECTS = $(am_dpkg_split_OBJECTS)
 am__DEPENDENCIES_1 =
-dpkg_split_DEPENDENCIES = ../libcompat/libcompat.a \
-	$(am__DEPENDENCIES_1) ../lib/libdpkg.a
+dpkg_split_DEPENDENCIES = ../lib/libdpkg.a \
+	$(am__DEPENDENCIES_1) ../libcompat/libcompat.a
 pkglibSCRIPT_INSTALL = $(INSTALL_SCRIPT)
 SCRIPTS = $(pkglib_SCRIPTS)
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
@@ -217,9 +217,9 @@
 	split.c
 
 dpkg_split_LDADD = \
-	../libcompat/libcompat.a \
 	$(LIBINTL) \
-	../lib/libdpkg.a
+	../lib/libdpkg.a \
+	../libcompat/libcompat.a
 
 pkglib_SCRIPTS = mksplit
 EXTRA_DIST = mksplit.pl
--- dpkg-1.14.23.orig/dselect/dselect.h
+++ dpkg-1.14.23/dselect/dselect.h
@@ -28,7 +28,11 @@
 
 #include <signal.h>
 #undef ERR
+#ifndef __INTERIX
 #include <ncursesw/curses.h>
+#else
+#include <curses.h>
+#endif
 
 struct helpmenuentry {
   char key;
--- dpkg-1.14.23.orig/dselect/main.cc
+++ dpkg-1.14.23/dselect/main.cc
@@ -37,7 +37,11 @@
 #include <ctype.h>
 #include <assert.h>
 
+#ifndef __INTERIX
 #include <ncursesw/term.h>
+#else
+#include <term.h>
+#endif
 
 extern "C" {
 #include <dpkg.h>
--- dpkg-1.14.23.orig/dselect/Makefile.am
+++ dpkg-1.14.23/dselect/Makefile.am
@@ -35,10 +35,10 @@
 	pkgtop.cc
 
 dselect_LDADD = \
-	../libcompat/libcompat.a \
 	$(LIBINTL) \
 	$(CURSES_LIBS) \
-	../lib/libdpkg.a
+	../lib/libdpkg.a \
+	../libcompat/libcompat.a
 
 
 EXTRA_DIST = keyoverride mkcurkeys.pl
@@ -46,7 +46,7 @@
 
 curkeys.$(OBJEXT): curkeys.h
 curkeys.h: $(srcdir)/keyoverride $(srcdir)/mkcurkeys.pl
-	cursesfile=`echo '#include <ncursesw/curses.h>' | \
+	cursesfile=`echo '#include <curses.h>' | \
 		$(CC) -E - | grep 'curses.h' | head -n 1 | \
 		sed -e 's/^[^"]*"//; s/".*$$//'`; \
 	if [ "$$cursesfile" = "" ]; then \
--- dpkg-1.14.23.orig/dselect/Makefile.in
+++ dpkg-1.14.23/dselect/Makefile.in
@@ -63,8 +63,8 @@
 	pkgsublist.$(OBJEXT) pkgtop.$(OBJEXT)
 dselect_OBJECTS = $(am_dselect_OBJECTS)
 am__DEPENDENCIES_1 =
-dselect_DEPENDENCIES = ../libcompat/libcompat.a $(am__DEPENDENCIES_1) \
-	$(am__DEPENDENCIES_1) ../lib/libdpkg.a
+dselect_DEPENDENCIES = ../lib/libdpkg.a $(am__DEPENDENCIES_1) \
+	$(am__DEPENDENCIES_1) ../libcompat/libcompat.a
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
 depcomp = $(SHELL) $(top_srcdir)/config/depcomp
 am__depfiles_maybe = depfiles
@@ -249,10 +249,10 @@
 	pkgtop.cc
 
 dselect_LDADD = \
-	../libcompat/libcompat.a \
 	$(LIBINTL) \
 	$(CURSES_LIBS) \
-	../lib/libdpkg.a
+	../lib/libdpkg.a \
+	../libcompat/libcompat.a
 
 EXTRA_DIST = keyoverride mkcurkeys.pl
 CLEANFILES = curkeys.h
@@ -640,7 +640,7 @@
 
 curkeys.$(OBJEXT): curkeys.h
 curkeys.h: $(srcdir)/keyoverride $(srcdir)/mkcurkeys.pl
-	cursesfile=`echo '#include <ncursesw/curses.h>' | \
+	cursesfile=`echo '#include <curses.h>' | \
 		$(CC) -E - | grep 'curses.h' | head -n 1 | \
 		sed -e 's/^[^"]*"//; s/".*$$//'`; \
 	if [ "$$cursesfile" = "" ]; then \
--- dpkg-1.14.23.orig/lib/dbmodify.c
+++ dpkg-1.14.23/lib/dbmodify.c
@@ -153,7 +153,11 @@
   switch (readwritereq) {
   case msdbrw_needsuperuser:
   case msdbrw_needsuperuserlockonly:
+#ifdef __INTERIX
+    if (getuid()!=197108 || geteuid()!=197108) /* Windows Administrator */
+#else
     if (getuid() || geteuid())
+#endif
       ohshit(_("requested operation requires superuser privilege"));
     /* fall through */
   case msdbrw_write: case msdbrw_writeifposs:
--- dpkg-1.14.23.orig/lib/getpgid.c
+++ dpkg-1.14.23/lib/getpgid.c
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+
+extern int errno;
+
+pid_t getpgid(pid_t pid)
+{
+    char procfile[25];
+    char stat_rec[40];
+    char inbuf[110];
+    char field1[10], field2[100];
+    FILE *in;
+    sprintf(procfile, "/proc/%d/stat", pid);
+    in = fopen(procfile, "r");
+    if (in == NULL)
+    {
+	errno = ESRCH; /* No such process */
+	return(-1);
+    }
+    
+    //Scan file for "pgid" entry
+    while(fgets(inbuf, sizeof(inbuf), in))
+    {
+	sscanf(inbuf, "%s\t%s\n", field1, field2);
+	if (strcmp(field1,"pgid") == 0)
+    	    return( (pid_t) atoi(field2));
+    }
+    errno = ENOSYS; /* Function not iimplemented */
+    return(-1);
+}
--- dpkg-1.14.23.orig/lib/Makefile.am
+++ dpkg-1.14.23/lib/Makefile.am
@@ -24,6 +24,7 @@
 	dump.c \
 	ehandle.c \
 	fields.c \
+	getpgid.c \
 	gettext.h \
 	lock.c \
 	log.c \
--- dpkg-1.14.23.orig/lib/Makefile.in
+++ dpkg-1.14.23/lib/Makefile.in
@@ -59,6 +59,7 @@
 am_libdpkg_a_OBJECTS = cleanup.$(OBJEXT) compat.$(OBJEXT) \
 	compression.$(OBJEXT) database.$(OBJEXT) dbmodify.$(OBJEXT) \
 	dump.$(OBJEXT) ehandle.$(OBJEXT) fields.$(OBJEXT) \
+	getpgid.$(OBJEXT) \
 	lock.$(OBJEXT) log.$(OBJEXT) md5.$(OBJEXT) mlib.$(OBJEXT) \
 	myopt.$(OBJEXT) myopt-util.$(OBJEXT) nfmalloc.$(OBJEXT) \
 	parse.$(OBJEXT) parsehelp.$(OBJEXT) showpkg.$(OBJEXT) \
@@ -227,6 +228,7 @@
 	dump.c \
 	ehandle.c \
 	fields.c \
+	getpgid.c \
 	gettext.h \
 	lock.c \
 	log.c \
--- dpkg-1.14.23.orig/lib/tarfn.c
+++ dpkg-1.14.23/lib/tarfn.c
@@ -80,11 +80,27 @@
 	unsigned int		i;
 	long			sum;
 	long			checksum;
+#ifdef __INTERIX
+	int			uid_root = 0;
+	int			gid_root = 0;
+#endif
 
 	if ( *h->UserName )
+#ifdef __INTERIX
+	    if ( 0 == strcmp(h->UserName, "root") ) {
+		uid_root = 1;
+	    } else
+#endif
 		passwd = getpwnam(h->UserName);
 	if ( *h->GroupName )
+#ifdef __INTERIX
+	    if ( 0 == strcmp(h->GroupName, "root") ) {
+		gid_root = 1;
+	    } else
+		group = getgrnam_nomembers(h->GroupName);
+#else
 		group = getgrnam(h->GroupName);
+#endif
 
 	d->Name = StoC(h->Name, sizeof(h->Name));
 	d->LinkName = StoC(h->LinkName, sizeof(h->LinkName));
@@ -101,10 +117,21 @@
 
 	if ( passwd )
 		d->UserID = passwd->pw_uid;
+#ifdef __INTERIX
+	else {
+		if ( uid_root || d->UserID == 0 || ! getpwuid(d->UserID) )
+			d->UserID = 197108; /* local Administrator */
+	}
+#endif
 
 	if ( group )
 		d->GroupID = group->gr_gid;
-
+#ifdef __INTERIX
+	else {
+		if ( gid_root || d->GroupID == 0 || ! getgrgid_nomembers(d->GroupID) )
+			d->GroupID = 131616; /* local Administrators group */
+	}
+#endif
 	
 	sum = ' ' * sizeof(h->Checksum);/* Treat checksum field as all blank */
 	for ( i = TarChecksumOffset; i > 0; i-- )
--- dpkg-1.14.23.orig/lib/triglib.c
+++ dpkg-1.14.23/lib/triglib.c
@@ -729,7 +729,11 @@
 			if (errno != EEXIST)
 				ohshite(_("unable to create triggers state"
 				          " directory `%.250s'"), triggersdir);
+#ifndef __INTERIX
 		} else if (chown(triggersdir, 0, 0)) {
+#else
+		} else if (chown(triggersdir, 197108, 131616)) {
+#endif
 			ohshite(_("unable to set ownership of triggers state"
 			          " directory `%.250s'"), triggersdir);
 		}
--- dpkg-1.14.23.orig/scripts/Dpkg/Shlibs/Objdump.pm
+++ dpkg-1.14.23/scripts/Dpkg/Shlibs/Objdump.pm
@@ -90,6 +90,10 @@
     my ($header, $result) = ("", 0);
     if (read(FILE, $header, 4) == 4) {
 	$result = 1 if ($header =~ /^\177ELF$/);
+	if ($header =~ /^MZ/) {
+	    seek(FILE, 60, 0) and read(FILE, $header, 4) == 4
+	    and ($header =~ /^PE\0\0$/) and $result = 1;
+	}
     }
     close(FILE);
     return $result;
@@ -161,6 +165,11 @@
 
 	if (/^DYNAMIC SYMBOL TABLE:/) {
 	    $section = "dynsym";
+	    if ($self->{format} eq "pei-i386") {
+		*parse_dynamic_symbol = \&parse_dynamic_symbol_pecoff;
+	    } else {
+		*parse_dynamic_symbol = \&parse_dynamic_symbol_elf;
+	    }
 	    next;
 	} elsif (/^DYNAMIC RELOCATION RECORDS/) {
 	    $section = "dynreloc";
@@ -169,6 +178,9 @@
 	} elsif (/^Dynamic Section:/) {
 	    $section = "dyninfo";
 	    next;
+	} elsif (/^Dynamic \(\.so\) Section:/) {
+	    $section = "dyninfo";
+	    next;
 	} elsif (/^Program Header:/) {
 	    $section = "header";
 	    next;
@@ -185,6 +197,8 @@
 	} elsif ($section eq "dynreloc") {
 	    if (/^\S+\s+(\S+)\s+(\S+)\s*$/) {
 		$self->{dynrelocs}{$2} = $1;
+	    } elsif (/^\S+\s+RELATIVE\s*$/) {
+		# ignore
 	    } else {
 		warning(_g("Couldn't parse dynamic relocation record: %s"), $_);
 	    }
@@ -249,7 +263,7 @@
 # (GLIBC_2.2) is the same but the symbol is hidden, a newer version of the
 # symbol exist
 
-sub parse_dynamic_symbol {
+sub parse_dynamic_symbol_elf {
     my ($self, $line) = @_;
     my $vis_re = '(\.protected|\.hidden|\.internal|0x\S+)';
     if ($line =~ /^[0-9a-f]+ (.{7})\s+(\S+)\s+[0-9a-f]+\s+(\S+)?(?:(?:\s+$vis_re)?\s+(\S+))/) {
@@ -295,6 +309,56 @@
     } elsif ($line =~ /^REG_G\d+\s+/) {
 	# Ignore some s390-specific output like
 	# REG_G6           g     R *UND*      0000000000000000              #scratch
+    } else {
+	warning(_g("Couldn't parse dynamic symbol definition: %s"), $line);
+    }
+}
+
+#
+# /lib/libc.so.3.5:     file format pei-i386
+#
+# DYNAMIC SYMBOL TABLE:
+# [  1](sec  1)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x0003fe06 __towupper
+# [  2](sec  1)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x0004029e __isatty2
+# [  3](sec  0)(fl 0x00)(ty   0)(scl 105) (nx 1) 0x00000000 _isatty2
+# AUX lnno 3 size 0x0 tagndx 2
+# [  5](sec  1)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x0004006e __dup
+# [  6](sec  1)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00040396 __pread
+# [  7](sec  0)(fl 0x00)(ty   0)(scl 105) (nx 1) 0x00000000 _pread
+#  |    |       |        |       |         |     |          |
+#  |    |       |        |       |         |     addr       symbol name
+#  |    |       |        |       |         code (=0) or data (=1)
+#  |    |       |        |       symbol class (2=strong, 105=weak alias)
+#  |    |       |        type (0=public, 20=private)
+#  |    |       flags (?)
+#  |    section (0=undefined)
+#  entry number
+# "AUX lnno" ? -> ignore
+
+sub parse_dynamic_symbol_pecoff {
+    my ($self, $line) = @_;
+    if ($line =~ /^\[ *\d+\]\(sec +(-?\d+)\)\(fl 0x00\)\(ty +(\d+)\)\(scl +(\d+)\) \(nx (\d)\) 0x([0-9a-f]{8}) (\S+)\s*/) {
+	my ($sect, $type, $scl, $nx, $addr, $name) = ($1, $2, $3, $4, $5, $6);
+
+	my $symbol = {
+		name => $name,
+		version => 'Base',
+		section => $sect,
+		dynamic => 1,
+		debug => 0,
+		type => '',
+		weak => ($scl==105),
+		local => ($type!=0),
+		global => 0,
+		visibility => '',
+		hidden => '',
+		defined => ($sect!=0 or $scl==105)
+	    };
+
+	# Register symbol
+	$self->add_dynamic_symbol($symbol);
+    } elsif ($line =~ /^AUX lnno 3 size 0x0 tagndx \d+\s*$/) {
+	# ignore
     } else {
 	warning(_g("Couldn't parse dynamic symbol definition: %s"), $line);
     }
--- dpkg-1.14.23.orig/src/help.c
+++ dpkg-1.14.23/src/help.c
@@ -24,6 +24,8 @@
 #include <unistd.h>
 #include <dirent.h>
 #include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -537,8 +539,23 @@
      */
     if (chmod(pathname,0600)) { *failed= N_("chmod"); return -1; }
   }
+  
+  /*
   if (unlink(pathname)) return -1;
   return 0;
+  
+  On interix unlink can return ETXTBSY, i.e. when replacing dpkg,
+  try to rename to /tmp in this case
+  */
+  
+  if (!unlink(pathname)) return 0;
+  /* unlink failed, try rename */
+  if (errno == ETXTBSY) {
+    char t[] = "/tmp/unlinkXXXXXX";
+    if (!rename(pathname, mktemp(t))) return 0;
+    *failed= N_("rename");
+  }
+  return -1;
 }
 
 void ensure_pathname_nonexisting(const char *pathname) {
--- dpkg-1.14.23.orig/src/Makefile.am
+++ dpkg-1.14.23/src/Makefile.am
@@ -28,8 +28,7 @@
 	update.c
 
 dpkg_LDADD = \
-	../libcompat/libcompat.a \
-	$(LIBINTL) ../lib/libdpkg.a $(ZLIB_LIBS) $(BZ2_LIBS) $(SELINUX_LIBS)
+	$(LIBINTL) ../lib/libdpkg.a ../libcompat/libcompat.a $(ZLIB_LIBS) $(BZ2_LIBS) $(SELINUX_LIBS)
 
 dpkg_query_SOURCES = \
 	errors.c \
@@ -37,17 +36,17 @@
 	query.c
 
 dpkg_query_LDADD = \
-	../libcompat/libcompat.a \
 	$(LIBINTL) \
-	../lib/libdpkg.a
+	../lib/libdpkg.a \
+	../libcompat/libcompat.a
 
 dpkg_trigger_SOURCES = \
 	trigcmd.c
 
 dpkg_trigger_LDADD = \
-	../libcompat/libcompat.a \
 	$(LIBINTL) \
-	../lib/libdpkg.a
+	../lib/libdpkg.a \
+	../libcompat/libcompat.a
 
 install-data-local:
 	$(mkdir_p) $(DESTDIR)$(admindir)/alternatives
--- dpkg-1.14.23.orig/src/Makefile.in
+++ dpkg-1.14.23/src/Makefile.in
@@ -62,18 +62,18 @@
 	update.$(OBJEXT)
 dpkg_OBJECTS = $(am_dpkg_OBJECTS)
 am__DEPENDENCIES_1 =
-dpkg_DEPENDENCIES = ../libcompat/libcompat.a $(am__DEPENDENCIES_1) \
-	../lib/libdpkg.a $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+dpkg_DEPENDENCIES = ../lib/libdpkg.a $(am__DEPENDENCIES_1) \
+	../libcompat/libcompat.a $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
 	$(am__DEPENDENCIES_1)
 am_dpkg_query_OBJECTS = errors.$(OBJEXT) filesdb.$(OBJEXT) \
 	query.$(OBJEXT)
 dpkg_query_OBJECTS = $(am_dpkg_query_OBJECTS)
-dpkg_query_DEPENDENCIES = ../libcompat/libcompat.a \
-	$(am__DEPENDENCIES_1) ../lib/libdpkg.a
+dpkg_query_DEPENDENCIES = ../lib/libdpkg.a \
+	$(am__DEPENDENCIES_1) ../libcompat/libcompat.a
 am_dpkg_trigger_OBJECTS = trigcmd.$(OBJEXT)
 dpkg_trigger_OBJECTS = $(am_dpkg_trigger_OBJECTS)
-dpkg_trigger_DEPENDENCIES = ../libcompat/libcompat.a \
-	$(am__DEPENDENCIES_1) ../lib/libdpkg.a
+dpkg_trigger_DEPENDENCIES = ../lib/libdpkg.a \
+	$(am__DEPENDENCIES_1) ../libcompat/libcompat.a
 DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
 depcomp = $(SHELL) $(top_srcdir)/config/depcomp
 am__depfiles_maybe = depfiles
@@ -239,8 +239,7 @@
 	update.c
 
 dpkg_LDADD = \
-	../libcompat/libcompat.a \
-	$(LIBINTL) ../lib/libdpkg.a $(ZLIB_LIBS) $(BZ2_LIBS) $(SELINUX_LIBS)
+	$(LIBINTL) ../lib/libdpkg.a ../libcompat/libcompat.a $(ZLIB_LIBS) $(BZ2_LIBS) $(SELINUX_LIBS)
 
 dpkg_query_SOURCES = \
 	errors.c \
@@ -248,17 +247,17 @@
 	query.c
 
 dpkg_query_LDADD = \
-	../libcompat/libcompat.a \
 	$(LIBINTL) \
-	../lib/libdpkg.a
+	../lib/libdpkg.a \
+	../libcompat/libcompat.a
 
 dpkg_trigger_SOURCES = \
 	trigcmd.c
 
 dpkg_trigger_LDADD = \
-	../libcompat/libcompat.a \
 	$(LIBINTL) \
-	../lib/libdpkg.a
+	../lib/libdpkg.a \
+	../libcompat/libcompat.a
 
 all: all-am
 
--- dpkg-1.14.23.orig/utils/start-stop-daemon.c
+++ dpkg-1.14.23/utils/start-stop-daemon.c
@@ -1,3 +1,11 @@
+/* start-stop-daemon disabled for now */
+int main(void)
+{
+    return 0;
+}
+
+#if 0
+
 /*
  * A rewrite of the original Debian's start-stop-daemon Perl script
  * in C (faster - it is executed many times during system startup).
@@ -1398,3 +1406,4 @@
 	fatal("Unable to start %s: %s", startas, strerror(errno));
 }
 
+#endif

