$NetBSD: patch-af,v 1.3 2012/07/18 22:10:21 marino Exp $ - don't declare own errno - fix build failure where gzgetc() is a macro (seen in a recent Linux bulk build) XXX: what this code is doing (mixing gzFile* and FILE* indiscriminately XXX: without even casting) is vile and will probably stop compiling at XXX: some point. JRM: That point arrived. The garbage spewed when compiled with JRM: zlib >= 1.2.6. Cast gzFile everywhere to fix it. JRM: David's gzgetc fix was changed; it broke too. --- misc/archive.c.orig 2004-12-12 01:16:54.000000000 +0000 +++ misc/archive.c @@ -48,9 +48,6 @@ Foundation, Inc., 675 Mass Ave, Cambridg #define MAXBUFSIZE 32768 -extern int errno; - - int fsizeof (const char *filename) // If USE_ZLIB is defined this function is very slow. Please avoid to use @@ -84,15 +81,15 @@ fsizeof (const char *filename) } #if 1 // This is not much faster than the other method - while (!gzeof (file)) - gzseek (file, 1024 * 1024, SEEK_CUR); - size = gztell (file); + while (!gzeof ((gzFile)file)) + gzseek ((gzFile)file, 1024 * 1024, SEEK_CUR); + size = gztell ((gzFile)file); #else // Is there a more efficient way to determine the uncompressed size? while ((bytesread = gzread (file, buf, MAXBUFSIZE)) > 0) size += bytesread; #endif - gzclose (file); + gzclose ((gzFile)file); return size; } else if (magic[0] == 'P' && magic[1] == 'K' && magic[2] == 0x03 && magic[3] == 0x04) @@ -384,7 +381,7 @@ fclose2 (FILE *file) if (fmode == FM_NORMAL) return fclose (file); else if (fmode == FM_GZIP) - return gzclose (file); + return gzclose ((gzFile)file); else if (fmode == FM_ZIP) { unzCloseCurrentFile (file); @@ -416,12 +413,12 @@ fseek2 (FILE *file, long offset, int mod if (mode == SEEK_END) // zlib doesn't support SEEK_END { // Note that this is _slow_... - while (!gzeof (file)) + while (!gzeof ((gzFile)file)) { - gzgetc (file); // necessary for _uncompressed_ files in order to set EOF - gzseek (file, 1024 * 1024, SEEK_CUR); + gzgetc ((gzFile)file); // necessary for _uncompressed_ files in order to set EOF + gzseek ((gzFile)file, 1024 * 1024, SEEK_CUR); } - offset += gztell (file); + offset += gztell ((gzFile)file); mode = SEEK_SET; } /* @@ -433,8 +430,8 @@ fseek2 (FILE *file, long offset, int mod DJGPP, Cygwin & GNU/Linux). It clears the EOF indicator. */ if (!finfo->compressed) - gzrewind (file); - return gzseek (file, offset, mode) == -1 ? -1 : 0; + gzrewind ((gzFile)file); + return gzseek ((gzFile)file, offset, mode) == -1 ? -1 : 0; } else if (finfo->fmode == FM_ZIP) { @@ -476,7 +473,7 @@ fread2 (void *buffer, size_t size, size_ return fread (buffer, size, number, file); else if (fmode == FM_GZIP) { - int n = gzread (file, buffer, number * size); + int n = gzread ((gzFile)file, buffer, number * size); return n / size; } else if (fmode == FM_ZIP) @@ -498,7 +495,7 @@ fgetc2 (FILE *file) if (fmode == FM_NORMAL) return fgetc (file); else if (fmode == FM_GZIP) - return gzgetc (file); + return gzgetc ((gzFile)file); else if (fmode == FM_ZIP) { char c; @@ -521,7 +518,7 @@ fgets2 (char *buffer, int maxlength, FIL return fgets (buffer, maxlength, file); else if (fmode == FM_GZIP) { - char *retval = gzgets (file, buffer, maxlength); + char *retval = gzgets ((gzFile)file, buffer, maxlength); return retval == Z_NULL ? NULL : retval; } else if (fmode == FM_ZIP) @@ -556,7 +553,7 @@ feof2 (FILE *file) if (fmode == FM_NORMAL) return feof (file); else if (fmode == FM_GZIP) - return gzeof (file); + return gzeof ((gzFile)file); else if (fmode == FM_ZIP) return unzeof (file); // returns feof() of the "current file" else @@ -578,7 +575,7 @@ fwrite2 (const void *buffer, size_t size return fwrite (buffer, size, number, file); else if (fmode == FM_GZIP) { - int n = gzwrite (file, (void *) buffer, number * size); + int n = gzwrite ((gzFile)file, (void *) buffer, number * size); return n / size; } else @@ -596,7 +593,7 @@ fputc2 (int character, FILE *file) if (fmode == FM_NORMAL) return fputc (character, file); else if (fmode == FM_GZIP) - return gzputc (file, character); + return gzputc ((gzFile)file, character); else return EOF; // writing to zip files is not supported #define fputc fputc2 @@ -612,7 +609,7 @@ ftell2 (FILE *file) if (fmode == FM_NORMAL) return ftell (file); else if (fmode == FM_GZIP) - return gztell (file); + return gztell ((gzFile)file); else if (fmode == FM_ZIP) return unztell (file); // returns ftell() of the "current file" else