--- xzlib.c	2013-11-16 16:38:59.000000000 -0500
+++ xzlib.c	2013-11-16 16:43:37.000000000 -0500
@@ -245,6 +245,20 @@
     return 0;
 }
 
+#ifdef HAVE_ZLIB_H
+static int
+xz_avail_zstrm(xz_statep state)
+{
+    int ret;
+    state->strm.avail_in = state->zstrm.avail_in;
+    state->strm.next_in = state->zstrm.next_in;
+    ret = xz_avail(state);
+    state->zstrm.avail_in = (uInt) state->strm.avail_in;
+    state->zstrm.next_in = (Bytef *) state->strm.next_in;
+    return ret;
+}
+#endif
+
 static int
 is_format_xz(xz_statep state)
 {
@@ -311,7 +325,7 @@
 #ifdef HAVE_ZLIB_H
 
 /* Get next byte from input, or -1 if end or error. */
-#define NEXT() ((strm->avail_in == 0 && xz_avail(state) == -1) ? -1 : \
+#define NEXT() ((strm->avail_in == 0 && xz_avail_zstrm(state) == -1) ? -1 : \
                 (strm->avail_in == 0 ? -1 : \
                  (strm->avail_in--, *(strm->next_in)++)))
 
