[darcs-users] darcs patch: resolve issue844: don't call gzwrite with zero length.
Matthias Andree
matthias.andree at gmx.de
Thu Nov 20 09:15:06 UTC 2008
Eric Kow <kowey at darcs.net> writes:
> Applied, thanks!
>
> So, I naively did a gzip < /dev/null > foo and got a non-empty file
> back... but I don't know if that's relevant (?), and Duncan (on IRC)
> says this looks good (although he wonders where those empty bytestrings
> are coming from)
Eric,
two late comments here (note I don't speak Haskell, so I'm using C
notation throughout):
1. I'd second Duncan that your getting a short file back is fine -- you
still get the .gz structured file container containing filename,
sizes, modes and such - see RFC1952.
2. gzip </dev/null is not the equivalent of gzwrite(foo, bar, 0). The
zlib equivalent would rather be opening a file for write and closing
it right again.
The actual problem is that there are subtle differences for 0-sized
writes in the gzwrite() interface as compared to write().
gzwrite(), as write(), returns the number of bytes successfully
written. Unlike write() however, gzwrite() uses 0 (rather than EOF
that is used by write(), and EOF is usually -1) to indicate error.
So with gzwrite() you cannot distinguish "successfully written 0
bytes" from "error writing 0 bytes".
For some reason, some zlib versions appear to trash their internal
CRC state on the 0-sized write (such as the one on openSUSE 11.0
i386), while others (such as the one on Ubuntu Hardy or Intrepid,
i386) don't.
HTH
Matthias
--
Matthias Andree
More information about the darcs-users
mailing list