| @@ -1,31 +1,146 @@ | | | @@ -1,31 +1,146 @@ |
1 | $NetBSD: patch-af,v 1.2 2012/05/10 22:11:20 dholland Exp $ | | 1 | $NetBSD: patch-af,v 1.3 2012/07/18 22:10:21 marino Exp $ |
2 | | | 2 | |
3 | - don't declare own errno | | 3 | - don't declare own errno |
4 | - fix build failure where gzgetc() is a macro (seen in a recent Linux | | 4 | - fix build failure where gzgetc() is a macro (seen in a recent Linux |
5 | bulk build) | | 5 | bulk build) |
6 | | | 6 | |
7 | XXX: what this code is doing (mixing gzFile* and FILE* indiscriminately | | 7 | XXX: what this code is doing (mixing gzFile* and FILE* indiscriminately |
8 | XXX: without even casting) is vile and will probably stop compiling at | | 8 | XXX: without even casting) is vile and will probably stop compiling at |
9 | XXX: some point. | | 9 | XXX: some point. |
10 | | | 10 | |
| | | 11 | JRM: That point arrived. The garbage spewed when compiled with |
| | | 12 | JRM: zlib >= 1.2.6. Cast gzFile everywhere to fix it. |
| | | 13 | JRM: David's gzgetc fix was changed; it broke too. |
| | | 14 | |
11 | --- misc/archive.c.orig 2004-12-12 01:16:54.000000000 +0000 | | 15 | --- misc/archive.c.orig 2004-12-12 01:16:54.000000000 +0000 |
12 | +++ misc/archive.c | | 16 | +++ misc/archive.c |
13 | @@ -48,9 +48,6 @@ Foundation, Inc., 675 Mass Ave, Cambridg | | 17 | @@ -48,9 +48,6 @@ Foundation, Inc., 675 Mass Ave, Cambridg |
14 | #define MAXBUFSIZE 32768 | | 18 | #define MAXBUFSIZE 32768 |
15 | | | 19 | |
16 | | | 20 | |
17 | -extern int errno; | | 21 | -extern int errno; |
18 | - | | 22 | - |
19 | - | | 23 | - |
20 | int | | 24 | int |
21 | fsizeof (const char *filename) | | 25 | fsizeof (const char *filename) |
22 | // If USE_ZLIB is defined this function is very slow. Please avoid to use | | 26 | // If USE_ZLIB is defined this function is very slow. Please avoid to use |
| | | 27 | @@ -84,15 +81,15 @@ fsizeof (const char *filename) |
| | | 28 | } |
| | | 29 | #if 1 |
| | | 30 | // This is not much faster than the other method |
| | | 31 | - while (!gzeof (file)) |
| | | 32 | - gzseek (file, 1024 * 1024, SEEK_CUR); |
| | | 33 | - size = gztell (file); |
| | | 34 | + while (!gzeof ((gzFile)file)) |
| | | 35 | + gzseek ((gzFile)file, 1024 * 1024, SEEK_CUR); |
| | | 36 | + size = gztell ((gzFile)file); |
| | | 37 | #else |
| | | 38 | // Is there a more efficient way to determine the uncompressed size? |
| | | 39 | while ((bytesread = gzread (file, buf, MAXBUFSIZE)) > 0) |
| | | 40 | size += bytesread; |
| | | 41 | #endif |
| | | 42 | - gzclose (file); |
| | | 43 | + gzclose ((gzFile)file); |
| | | 44 | return size; |
| | | 45 | } |
| | | 46 | else if (magic[0] == 'P' && magic[1] == 'K' && magic[2] == 0x03 && magic[3] == 0x04) |
| | | 47 | @@ -384,7 +381,7 @@ fclose2 (FILE *file) |
| | | 48 | if (fmode == FM_NORMAL) |
| | | 49 | return fclose (file); |
| | | 50 | else if (fmode == FM_GZIP) |
| | | 51 | - return gzclose (file); |
| | | 52 | + return gzclose ((gzFile)file); |
| | | 53 | else if (fmode == FM_ZIP) |
| | | 54 | { |
| | | 55 | unzCloseCurrentFile (file); |
| | | 56 | @@ -416,12 +413,12 @@ fseek2 (FILE *file, long offset, int mod |
| | | 57 | if (mode == SEEK_END) // zlib doesn't support SEEK_END |
| | | 58 | { |
| | | 59 | // Note that this is _slow_... |
| | | 60 | - while (!gzeof (file)) |
| | | 61 | + while (!gzeof ((gzFile)file)) |
| | | 62 | { |
| | | 63 | - gzgetc (file); // necessary for _uncompressed_ files in order to set EOF |
| | | 64 | - gzseek (file, 1024 * 1024, SEEK_CUR); |
| | | 65 | + gzgetc ((gzFile)file); // necessary for _uncompressed_ files in order to set EOF |
| | | 66 | + gzseek ((gzFile)file, 1024 * 1024, SEEK_CUR); |
| | | 67 | } |
| | | 68 | - offset += gztell (file); |
| | | 69 | + offset += gztell ((gzFile)file); |
| | | 70 | mode = SEEK_SET; |
| | | 71 | } |
| | | 72 | /* |
| | | 73 | @@ -433,8 +430,8 @@ fseek2 (FILE *file, long offset, int mod |
| | | 74 | DJGPP, Cygwin & GNU/Linux). It clears the EOF indicator. |
| | | 75 | */ |
| | | 76 | if (!finfo->compressed) |
| | | 77 | - gzrewind (file); |
| | | 78 | - return gzseek (file, offset, mode) == -1 ? -1 : 0; |
| | | 79 | + gzrewind ((gzFile)file); |
| | | 80 | + return gzseek ((gzFile)file, offset, mode) == -1 ? -1 : 0; |
| | | 81 | } |
| | | 82 | else if (finfo->fmode == FM_ZIP) |
| | | 83 | { |
| | | 84 | @@ -476,7 +473,7 @@ fread2 (void *buffer, size_t size, size_ |
| | | 85 | return fread (buffer, size, number, file); |
| | | 86 | else if (fmode == FM_GZIP) |
| | | 87 | { |
| | | 88 | - int n = gzread (file, buffer, number * size); |
| | | 89 | + int n = gzread ((gzFile)file, buffer, number * size); |
| | | 90 | return n / size; |
| | | 91 | } |
| | | 92 | else if (fmode == FM_ZIP) |
23 | @@ -498,7 +495,7 @@ fgetc2 (FILE *file) | | 93 | @@ -498,7 +495,7 @@ fgetc2 (FILE *file) |
24 | if (fmode == FM_NORMAL) | | 94 | if (fmode == FM_NORMAL) |
25 | return fgetc (file); | | 95 | return fgetc (file); |
26 | else if (fmode == FM_GZIP) | | 96 | else if (fmode == FM_GZIP) |
27 | - return gzgetc (file); | | 97 | - return gzgetc (file); |
28 | + return gzgetc ((struct gzFile *)file); | | 98 | + return gzgetc ((gzFile)file); |
29 | else if (fmode == FM_ZIP) | | 99 | else if (fmode == FM_ZIP) |
30 | { | | 100 | { |
31 | char c; | | 101 | char c; |
| | | 102 | @@ -521,7 +518,7 @@ fgets2 (char *buffer, int maxlength, FIL |
| | | 103 | return fgets (buffer, maxlength, file); |
| | | 104 | else if (fmode == FM_GZIP) |
| | | 105 | { |
| | | 106 | - char *retval = gzgets (file, buffer, maxlength); |
| | | 107 | + char *retval = gzgets ((gzFile)file, buffer, maxlength); |
| | | 108 | return retval == Z_NULL ? NULL : retval; |
| | | 109 | } |
| | | 110 | else if (fmode == FM_ZIP) |
| | | 111 | @@ -556,7 +553,7 @@ feof2 (FILE *file) |
| | | 112 | if (fmode == FM_NORMAL) |
| | | 113 | return feof (file); |
| | | 114 | else if (fmode == FM_GZIP) |
| | | 115 | - return gzeof (file); |
| | | 116 | + return gzeof ((gzFile)file); |
| | | 117 | else if (fmode == FM_ZIP) |
| | | 118 | return unzeof (file); // returns feof() of the "current file" |
| | | 119 | else |
| | | 120 | @@ -578,7 +575,7 @@ fwrite2 (const void *buffer, size_t size |
| | | 121 | return fwrite (buffer, size, number, file); |
| | | 122 | else if (fmode == FM_GZIP) |
| | | 123 | { |
| | | 124 | - int n = gzwrite (file, (void *) buffer, number * size); |
| | | 125 | + int n = gzwrite ((gzFile)file, (void *) buffer, number * size); |
| | | 126 | return n / size; |
| | | 127 | } |
| | | 128 | else |
| | | 129 | @@ -596,7 +593,7 @@ fputc2 (int character, FILE *file) |
| | | 130 | if (fmode == FM_NORMAL) |
| | | 131 | return fputc (character, file); |
| | | 132 | else if (fmode == FM_GZIP) |
| | | 133 | - return gzputc (file, character); |
| | | 134 | + return gzputc ((gzFile)file, character); |
| | | 135 | else |
| | | 136 | return EOF; // writing to zip files is not supported |
| | | 137 | #define fputc fputc2 |
| | | 138 | @@ -612,7 +609,7 @@ ftell2 (FILE *file) |
| | | 139 | if (fmode == FM_NORMAL) |
| | | 140 | return ftell (file); |
| | | 141 | else if (fmode == FM_GZIP) |
| | | 142 | - return gztell (file); |
| | | 143 | + return gztell ((gzFile)file); |
| | | 144 | else if (fmode == FM_ZIP) |
| | | 145 | return unztell (file); // returns ftell() of the "current file" |
| | | 146 | else |