@@ -94,114 +94,114 @@ static void test_compress(unsigned char *compr, z_uintmax_t comprLen, unsigned c
9494 printf ("uncompress(): %s\n" , (char * )uncompr );
9595}
9696
97- // / * ===========================================================================
98- // * Test read/write of .gz files
99- // */
100- // static void test_gzio(const char *fname, unsigned char *uncompr, z_size_t uncomprLen) {
101- // #ifdef NO_GZCOMPRESS
102- // fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n");
103- // #else
104- // int err;
105- // size_t read;
106- // size_t len = strlen(hello)+1;
107- // gzFile file;
108- // z_off64_t pos;
109- // z_off64_t comprLen;
110- //
111- // /* Write gz file with test data */
112- // file = PREFIX(gzopen)(fname, "wb");
113- // if (file == NULL)
114- // error("gzopen error\n");
115- // /* Write hello, hello! using gzputs and gzprintf */
116- // PREFIX(gzputc)(file, 'h');
117- // if (PREFIX(gzputs)(file, "ello") != 4)
118- // error("gzputs err: %s\n", PREFIX(gzerror)(file, &err));
119- // if (PREFIX(gzprintf)(file, ", %s!", "hello") != 8)
120- // error("gzprintf err: %s\n", PREFIX(gzerror)(file, &err));
121- // /* Write string null-teriminator using gzseek */
122- // if (PREFIX(gzseek)(file, 1L, SEEK_CUR) < 0)
123- // error("gzseek error, gztell=%ld\n", (long)PREFIX(gztell)(file));
124- // /* Write hello, hello! using gzfwrite using best compression level */
125- // if (PREFIX(gzsetparams)(file, Z_BEST_COMPRESSION, Z_DEFAULT_STRATEGY) != Z_OK)
126- // error("gzsetparams err: %s\n", PREFIX(gzerror)(file, &err));
127- // if (PREFIX(gzfwrite)(hello, len, 1, file) == 0)
128- // error("gzfwrite err: %s\n", PREFIX(gzerror)(file, &err));
129- // /* Flush compressed bytes to file */
130- // if (PREFIX(gzflush)(file, Z_SYNC_FLUSH) != Z_OK)
131- // error("gzflush err: %s\n", PREFIX(gzerror)(file, &err));
132- // comprLen = PREFIX(gzoffset)(file);
133- // if (comprLen <= 0)
134- // error("gzoffset err: %s\n", PREFIX(gzerror)(file, &err));
135- // PREFIX(gzclose)(file);
136- //
137- // /* Open gz file we previously wrote */
138- // file = PREFIX(gzopen)(fname, "rb");
139- // if (file == NULL)
140- // error("gzopen error\n");
141- //
142- // /* Read uncompressed data - hello, hello! string twice */
143- // strcpy((char*)uncompr, "garbages");
144- // if (PREFIX(gzread)(file, uncompr, (unsigned)uncomprLen) != (int)(len + len))
145- // error("gzread err: %s\n", PREFIX(gzerror)(file, &err));
146- // if (strcmp((char*)uncompr, hello))
147- // error("bad gzread: %s\n", (char*)uncompr);
148- // else
149- // printf("gzread(): %s\n", (char*)uncompr);
150- // /* Check position at the end of the gz file */
151- // if (PREFIX(gzeof)(file) != 1)
152- // error("gzeof err: not reporting end of stream\n");
153- //
154- // /* Seek backwards mid-string and check char reading with gzgetc and gzungetc */
155- // pos = PREFIX(gzseek)(file, -22L, SEEK_CUR);
156- // if (pos != 6 || PREFIX(gztell)(file) != pos)
157- // error("gzseek error, pos=%ld, gztell=%ld\n", (long)pos, (long)PREFIX(gztell)(file));
158- // if (PREFIX(gzgetc)(file) != ' ')
159- // error("gzgetc error\n");
160- // if (PREFIX(gzungetc)(' ', file) != ' ')
161- // error("gzungetc error\n");
162- // /* Read first hello, hello! string with gzgets */
163- // strcpy((char*)uncompr, "garbages");
164- // PREFIX(gzgets)(file, (char*)uncompr, (int)uncomprLen);
165- // if (strlen((char*)uncompr) != 7) /* " hello!" */
166- // error("gzgets err after gzseek: %s\n", PREFIX(gzerror)(file, &err));
167- // if (strcmp((char*)uncompr, hello + 6))
168- // error("bad gzgets after gzseek\n");
169- // else
170- // printf("gzgets() after gzseek: %s\n", (char*)uncompr);
171- // /* Seek to second hello, hello! string */
172- // pos = PREFIX(gzseek)(file, 14L, SEEK_SET);
173- // if (pos != 14 || PREFIX(gztell)(file) != pos)
174- // error("gzseek error, pos=%ld, gztell=%ld\n", (long)pos, (long)PREFIX(gztell)(file));
175- // /* Check position not at end of file */
176- // if (PREFIX(gzeof)(file) != 0)
177- // error("gzeof err: reporting end of stream\n");
178- // /* Read first hello, hello! string with gzfread */
179- // strcpy((char*)uncompr, "garbages");
180- // read = PREFIX(gzfread)(uncompr, uncomprLen, 1, file);
181- // if (strcmp((const char *)uncompr, hello) != 0)
182- // error("bad gzgets\n");
183- // else
184- // printf("gzgets(): %s\n", (char*)uncompr);
185- // pos = PREFIX(gzoffset)(file);
186- // if (pos < 0 || pos != (comprLen + 10))
187- // error("gzoffset err: wrong offset at end\n");
188- // /* Trigger an error and clear it with gzclearerr */
189- // PREFIX(gzfread)(uncompr, (size_t)-1, (size_t)-1, file);
190- // PREFIX(gzerror)(file, &err);
191- // if (err == 0)
192- // error("gzerror err: no error returned\n");
193- // PREFIX(gzclearerr)(file);
194- // PREFIX(gzerror)(file, &err);
195- // if (err != 0)
196- // error("gzclearerr err: not zero %d\n", err);
197- //
198- // PREFIX(gzclose)(file);
199- //
200- // if (PREFIX(gzclose)(NULL) != Z_STREAM_ERROR)
201- // error("gzclose unexpected return when handle null\n");
202- // Z_UNUSED(read);
203- // #endif
204- // }
97+ /* ===========================================================================
98+ * Test read/write of .gz files
99+ */
100+ static void test_gzio (const char * fname , unsigned char * uncompr , z_size_t uncomprLen ) {
101+ #ifdef NO_GZCOMPRESS
102+ fprintf (stderr , "NO_GZCOMPRESS -- gz* functions cannot compress\n" );
103+ #else
104+ int err ;
105+ size_t read ;
106+ size_t len = strlen (hello )+ 1 ;
107+ gzFile file ;
108+ z_off64_t pos ;
109+ z_off64_t comprLen ;
110+
111+ /* Write gz file with test data */
112+ file = PREFIX (gzopen )(fname , "wb" );
113+ if (file == NULL )
114+ error ("gzopen error\n" );
115+ /* Write hello, hello! using gzputs and gzprintf */
116+ PREFIX (gzputc )(file , 'h' );
117+ if (PREFIX (gzputs )(file , "ello" ) != 4 )
118+ error ("gzputs err: %s\n" , PREFIX (gzerror )(file , & err ));
119+ if (PREFIX (gzprintf )(file , ", %s!" , "hello" ) != 8 )
120+ error ("gzprintf err: %s\n" , PREFIX (gzerror )(file , & err ));
121+ /* Write string null-teriminator using gzseek */
122+ if (PREFIX (gzseek )(file , 1L , SEEK_CUR ) < 0 )
123+ error ("gzseek error, gztell=%ld\n" , (long )PREFIX (gztell )(file ));
124+ /* Write hello, hello! using gzfwrite using best compression level */
125+ if (PREFIX (gzsetparams )(file , Z_BEST_COMPRESSION , Z_DEFAULT_STRATEGY ) != Z_OK )
126+ error ("gzsetparams err: %s\n" , PREFIX (gzerror )(file , & err ));
127+ if (PREFIX (gzfwrite )(hello , len , 1 , file ) == 0 )
128+ error ("gzfwrite err: %s\n" , PREFIX (gzerror )(file , & err ));
129+ /* Flush compressed bytes to file */
130+ if (PREFIX (gzflush )(file , Z_SYNC_FLUSH ) != Z_OK )
131+ error ("gzflush err: %s\n" , PREFIX (gzerror )(file , & err ));
132+ comprLen = PREFIX (gzoffset )(file );
133+ if (comprLen <= 0 )
134+ error ("gzoffset err: %s\n" , PREFIX (gzerror )(file , & err ));
135+ PREFIX (gzclose )(file );
136+
137+ /* Open gz file we previously wrote */
138+ file = PREFIX (gzopen )(fname , "rb" );
139+ if (file == NULL )
140+ error ("gzopen error\n" );
141+
142+ /* Read uncompressed data - hello, hello! string twice */
143+ strcpy ((char * )uncompr , "garbages" );
144+ if (PREFIX (gzread )(file , uncompr , (unsigned )uncomprLen ) != (int )(len + len ))
145+ error ("gzread err: %s\n" , PREFIX (gzerror )(file , & err ));
146+ if (strcmp ((char * )uncompr , hello ))
147+ error ("bad gzread: %s\n" , (char * )uncompr );
148+ else
149+ printf ("gzread(): %s\n" , (char * )uncompr );
150+ /* Check position at the end of the gz file */
151+ if (PREFIX (gzeof )(file ) != 1 )
152+ error ("gzeof err: not reporting end of stream\n" );
153+
154+ /* Seek backwards mid-string and check char reading with gzgetc and gzungetc */
155+ pos = PREFIX (gzseek )(file , -22L , SEEK_CUR );
156+ if (pos != 6 || PREFIX (gztell )(file ) != pos )
157+ error ("gzseek error, pos=%ld, gztell=%ld\n" , (long )pos , (long )PREFIX (gztell )(file ));
158+ if (PREFIX (gzgetc )(file ) != ' ' )
159+ error ("gzgetc error\n" );
160+ if (PREFIX (gzungetc )(' ' , file ) != ' ' )
161+ error ("gzungetc error\n" );
162+ /* Read first hello, hello! string with gzgets */
163+ strcpy ((char * )uncompr , "garbages" );
164+ PREFIX (gzgets )(file , (char * )uncompr , (int )uncomprLen );
165+ if (strlen ((char * )uncompr ) != 7 ) /* " hello!" */
166+ error ("gzgets err after gzseek: %s\n" , PREFIX (gzerror )(file , & err ));
167+ if (strcmp ((char * )uncompr , hello + 6 ))
168+ error ("bad gzgets after gzseek\n" );
169+ else
170+ printf ("gzgets() after gzseek: %s\n" , (char * )uncompr );
171+ /* Seek to second hello, hello! string */
172+ pos = PREFIX (gzseek )(file , 14L , SEEK_SET );
173+ if (pos != 14 || PREFIX (gztell )(file ) != pos )
174+ error ("gzseek error, pos=%ld, gztell=%ld\n" , (long )pos , (long )PREFIX (gztell )(file ));
175+ /* Check position not at end of file */
176+ if (PREFIX (gzeof )(file ) != 0 )
177+ error ("gzeof err: reporting end of stream\n" );
178+ /* Read first hello, hello! string with gzfread */
179+ strcpy ((char * )uncompr , "garbages" );
180+ read = PREFIX (gzfread )(uncompr , uncomprLen , 1 , file );
181+ if (strcmp ((const char * )uncompr , hello ) != 0 )
182+ error ("bad gzgets\n" );
183+ else
184+ printf ("gzgets(): %s\n" , (char * )uncompr );
185+ pos = PREFIX (gzoffset )(file );
186+ if (pos < 0 || pos != (comprLen + 10 ))
187+ error ("gzoffset err: wrong offset at end\n" );
188+ /* Trigger an error and clear it with gzclearerr */
189+ PREFIX (gzfread )(uncompr , (size_t )-1 , (size_t )-1 , file );
190+ PREFIX (gzerror )(file , & err );
191+ if (err == 0 )
192+ error ("gzerror err: no error returned\n" );
193+ PREFIX (gzclearerr )(file );
194+ PREFIX (gzerror )(file , & err );
195+ if (err != 0 )
196+ error ("gzclearerr err: not zero %d\n" , err );
197+
198+ PREFIX (gzclose )(file );
199+
200+ if (PREFIX (gzclose )(NULL ) != Z_STREAM_ERROR )
201+ error ("gzclose unexpected return when handle null\n" );
202+ Z_UNUSED (read );
203+ #endif
204+ }
205205
206206/* ===========================================================================
207207 * Test deflate() with small buffers
@@ -977,8 +977,8 @@ int main(int argc, char *argv[]) {
977977
978978 test_compress (compr , comprLen , uncompr , uncomprLen );
979979
980- // test_gzio((argc > 1 ? argv[1] : TESTFILE),
981- // uncompr, uncomprLen);
980+ test_gzio ((argc > 1 ? argv [1 ] : TESTFILE ),
981+ uncompr , uncomprLen );
982982
983983 test_deflate (compr , comprLen );
984984 test_inflate (compr , comprLen , uncompr , uncomprLen );
0 commit comments