title: gzread fails after successful gzdopen on mswin32
body: <p>There seems to be something broken in the windows build for zlib 1.2.8. According to USAGE.txt in <a href="http://zlib.net/zlib128-dll.zip" rel="nofollow noreferrer">http://zlib.net/zlib128-dll.zip</a> (from zlib.net) and the man pages for gzread and gzdopen, the code should work. Can anyone enlighten me, please? BTW, I have tested this code on darwin (using zlib 1.2.5) and linux (using zlib 1.2.1) where gzdopen works.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;fcntl.h&gt;
  #include "zlib.h"
  
  int main(int argc, char *argv[]) {
          char            buffer[500];
          int             len;
          gzFile          gin;
          const char      *errmsg;
          int             errnum;
          char            *fun      = argv[1];
          char            *filename = argv[2];
          printf("fun: %s filename: %s\n", fun, filename);
          printf("zlib version: %s\n", zlibVersion());
          if (!strcmp(fun, "gzdopen")) {
                  int fd = open(filename, O_RDONLY);
                  printf("open returned %d\n", fd);
                  gin = gzdopen(fd, "rb");
          }
          if (!strcmp(fun, "gzopen"))
                  gin = gzopen(filename, "rb");
          printf("gzopen returned %p\n", gin);
          len = gzread(gin, buffer, sizeof(buffer));
          fprintf(stderr, "gzread() returned %d\n", len);
          errmsg = gzerror(gin, &amp;errnum);
          fprintf(stderr, "gzerror() returned '%s'; errnum=%d\n", errmsg, errnum);
          return 0;
  }
  </code></pre>
  
  <p>And here's what I did:</p>
  
  <pre><code>C:\decompress&gt; cl test.c /Iinclude lib/zdll.lib
  Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
  Copyright (C) Microsoft Corp 1984-1998. All rights reserved.
  
  test.c
  Microsoft (R) Incremental Linker Version 6.00.8447
  Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
  
  C:\decompress&gt; gzip -c &lt; test.c &gt; test.c.gz
  
  C:\decompress&gt;test gzdopen test.c.gz
  fun: gzdopen filename: test.c.gz
  zlib version: 1.2.8
  open returned 3
  gzopen returned 00332CE0
  gzread() returned -1
  gzerror() returned '&lt;fd:3&gt;: Bad file descriptor'; errnum=-1
  
  C:\decompress&gt;test gzopen test.c.gz
  fun: gzopen filename: test.c.gz
  zlib version: 1.2.8
  gzopen returned 00332CC0
  gzread() returned 500
  gzerror() returned ''; errnum=0
  </code></pre>