[9changes] patch: gunzip-empty-file

50 views
Skip to first unread message

9cha...@9grid.fr

unread,
May 13, 2015, 6:00:38 AM5/13/15
to 9cha...@googlegroups.com
This has annoted me forever. Make gunzip report empty files as
what they are than what they are not (not a valid gzip file).

empty files are relitively common when pickey websites refuse to
downloads by hget as they have no respect for the "Plan9"
user agent header (sigh).

Reference: /n/sources/patch/gunzip-empty-file
Date: Wed May 13 11:53:04 CES 2015
Signed-off-by: st...@quintile.net

--- /sys/src/cmd/gzip/gunzip.c Wed May 13 11:41:58 2015
+++ /sys/src/cmd/gzip/gunzip.c Wed May 13 11:41:54 2015
@@ -95,7 +95,7 @@
gunzipf(char *file, int stdout)
{
char ofile[256], *s;
- int ofd, ifd, ok;
+ int ofd, ifd, ok, n;

infile = file;
ifd = open(file, OREAD);
@@ -105,8 +105,11 @@
}

Binit(&bin, ifd, OREAD);
- if(Bgetc(&bin) != GZMAGIC1 || Bgetc(&bin) != GZMAGIC2 || Bgetc(&bin) != GZDEFLATE){
- fprint(2, "gunzip: %s is not a gzip deflate file\n", file);
+ if((n = Bgetc(&bin)) != GZMAGIC1 || Bgetc(&bin) != GZMAGIC2 || Bgetc(&bin) != GZDEFLATE){
+ if(n == -1)
+ fprint(2, "gunzip: %s empty file\n", file);
+ else
+ fprint(2, "gunzip: %s is not a gzip deflate file\n", file);
Bterm(&bin);
close(ifd);
return 0;
Reply all
Reply to author
Forward
0 new messages