diff -Paur --no-dereference -- gzip.upstream/build-aux/config.sub gzip/build-aux/config.sub
--- gzip.upstream/build-aux/config.sub
+++ gzip/build-aux/config.sub
@@ -1348,7 +1348,7 @@
 	      | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
 	      | -sym* | -kopensolaris* \
 	      | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
-	      | -aos* | -aros* \
+	      | -aos* | -aros* | -sortix* \
 	      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
 	      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
 	      | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
diff -Paur --no-dereference -- gzip.upstream/gunzip.in gzip/gunzip.in
--- gzip.upstream/gunzip.in
+++ gzip/gunzip.in
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!sh
 # Uncompress files.  This is the inverse of gzip.
 
 # Copyright (C) 2007 Free Software Foundation
diff -Paur --no-dereference -- gzip.upstream/gzexe.in gzip/gzexe.in
--- gzip.upstream/gzexe.in
+++ gzip/gzexe.in
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!sh
 # gzexe: compressor for Unix executables.
 # Use this only for binaries that you do not use frequently.
 #
diff -Paur --no-dereference -- gzip.upstream/lib/fcntl.c gzip/lib/fcntl.c
--- gzip.upstream/lib/fcntl.c
+++ gzip/lib/fcntl.c
@@ -181,7 +181,7 @@
         result = dupfd (fd, target, 0);
         break;
       }
-#elif FCNTL_DUPFD_BUGGY || REPLACE_FCHDIR
+#elif (FCNTL_DUPFD_BUGGY || REPLACE_FCHDIR) && !defined(__sortix__)
     case F_DUPFD:
       {
         int target = va_arg (arg, int);
diff -Paur --no-dereference -- gzip.upstream/lib/freadahead.c gzip/lib/freadahead.c
--- gzip.upstream/lib/freadahead.c
+++ gzip/lib/freadahead.c
@@ -22,6 +22,10 @@
 #include <stdlib.h>
 #include "stdio-impl.h"
 
+#if defined __sortix__
+#include <FILE.h>
+#endif
+
 size_t
 freadahead (FILE *fp)
 {
@@ -84,6 +88,10 @@
   if (fp->state == 4 /* WR */ || fp->rp >= fp->wp)
     return 0;
   return fp->wp - fp->rp;
+#elif defined __sortix__
+  if ( !(fp->flags & _FILE_LAST_READ) )
+    return 0;
+  return fp->amount_input_buffered - fp->offset_input_buffer;
 #elif defined SLOW_BUT_NO_HACKS     /* users can define this */
   abort ();
   return 0;
diff -Paur --no-dereference -- gzip.upstream/lib/fseeko.c gzip/lib/fseeko.c
--- gzip.upstream/lib/fseeko.c
+++ gzip/lib/fseeko.c
@@ -99,6 +99,8 @@
 #elif defined EPLAN9                /* Plan9 */
   if (fp->rp == fp->buf
       && fp->wp == fp->buf)
+#elif defined __sortix__
+  if (0) /* wtf is this shit - sortix handles fseeko just fine. */
 #else
   #error "Please port gnulib fseeko.c to your platform! Look at the code in fpurge.c, then report this to bug-gnulib."
 #endif
diff -Paur --no-dereference -- gzip.upstream/lib/fseterr.c gzip/lib/fseterr.c
--- gzip.upstream/lib/fseterr.c
+++ gzip/lib/fseterr.c
@@ -23,6 +23,10 @@
 
 #include "stdio-impl.h"
 
+#if defined __sortix__
+#include <FILE.h>
+#endif
+
 void
 fseterr (FILE *fp)
 {
@@ -48,6 +52,8 @@
 #elif defined EPLAN9                /* Plan9 */
   if (fp->state != 0 /* CLOSED */)
     fp->state = 5 /* ERR */;
+#elif defined __sortix__
+  fp->flags |= _FILE_STATUS_ERROR;
 #elif 0                             /* unknown  */
   /* Portable fallback, based on an idea by Rich Felker.
      Wow! 6 system calls for something that is just a bit operation!
diff -Paur --no-dereference -- gzip.upstream/Makefile.am gzip/Makefile.am
--- gzip.upstream/Makefile.am
+++ gzip/Makefile.am
@@ -82,7 +82,6 @@
 SUFFIXES = .in
 .in:
 	$(AM_V_GEN)sed \
-		-e 's|/bin/sh|$(SHELL)|g' \
 		-e 's|[@]bindir@|'\''$(bindir)'\''|g' \
 		-e 's|[@]VERSION@|$(VERSION)|g' \
 		$(srcdir)/$@.in >$@-t \
diff -Paur --no-dereference -- gzip.upstream/Makefile.in gzip/Makefile.in
--- gzip.upstream/Makefile.in
+++ gzip/Makefile.in
@@ -2102,7 +2102,6 @@
 	$(AM_V_GEN)./gzip < $(srcdir)/gzip.doc >$@-t && mv $@-t $@
 .in:
 	$(AM_V_GEN)sed \
-		-e 's|/bin/sh|$(SHELL)|g' \
 		-e 's|[@]bindir@|'\''$(bindir)'\''|g' \
 		-e 's|[@]VERSION@|$(VERSION)|g' \
 		$(srcdir)/$@.in >$@-t \
diff -Paur --no-dereference -- gzip.upstream/zcat.in gzip/zcat.in
--- gzip.upstream/zcat.in
+++ gzip/zcat.in
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!sh
 # Uncompress files to standard output.
 
 # Copyright (C) 2007 Free Software Foundation
diff -Paur --no-dereference -- gzip.upstream/zcmp.in gzip/zcmp.in
--- gzip.upstream/zcmp.in
+++ gzip/zcmp.in
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!sh
 # Compare the uncompressed contents of compressed files, byte by byte.
 
 # Copyright (C) 2007, 2010-2012 Free Software Foundation, Inc.
diff -Paur --no-dereference -- gzip.upstream/zdiff.in gzip/zdiff.in
--- gzip.upstream/zdiff.in
+++ gzip/zdiff.in
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!sh
 # sh is buggy on RS/6000 AIX 3.2. Replace above line with #!/bin/ksh
 
 # Copyright (C) 1998, 2002, 2006, 2007, 2009 Free Software Foundation
diff -Paur --no-dereference -- gzip.upstream/zegrep.in gzip/zegrep.in
--- gzip.upstream/zegrep.in
+++ gzip/zegrep.in
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!sh
 bindir=@bindir@
 case $1 in
 --__bindir) bindir=${2?}; shift; shift;;
diff -Paur --no-dereference -- gzip.upstream/zfgrep.in gzip/zfgrep.in
--- gzip.upstream/zfgrep.in
+++ gzip/zfgrep.in
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!sh
 bindir=@bindir@
 case $1 in
 --__bindir) bindir=${2?}; shift; shift;;
diff -Paur --no-dereference -- gzip.upstream/zforce.in gzip/zforce.in
--- gzip.upstream/zforce.in
+++ gzip/zforce.in
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!sh
 # zforce: force a gz extension on all gzip files so that gzip will not
 # compress them twice.
 #
diff -Paur --no-dereference -- gzip.upstream/zgrep.in gzip/zgrep.in
--- gzip.upstream/zgrep.in
+++ gzip/zgrep.in
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!sh
 
 # zgrep -- a wrapper around a grep program that decompresses files as needed
 # Adapted from a version sent by Charles Levert <charles@comm.polymtl.ca>
diff -Paur --no-dereference -- gzip.upstream/zless.in gzip/zless.in
--- gzip.upstream/zless.in
+++ gzip/zless.in
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!sh
 
 # Copyright (C) 1998, 2002, 2006, 2007 Free Software Foundation
 
diff -Paur --no-dereference -- gzip.upstream/zmore.in gzip/zmore.in
--- gzip.upstream/zmore.in
+++ gzip/zmore.in
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!sh
 
 # Copyright (C) 2001, 2002, 2007, 2010 Free Software Foundation
 # Copyright (C) 1992, 1993 Jean-loup Gailly
diff -Paur --no-dereference -- gzip.upstream/znew.in gzip/znew.in
--- gzip.upstream/znew.in
+++ gzip/znew.in
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!sh
 
 # Copyright (C) 1998, 2002, 2004, 2007, 2010 Free Software Foundation
 # Copyright (C) 1993 Jean-loup Gailly
