MCPcopy Create free account
hub / github.com/F-Stack/f-stack / test_gzio

Function test_gzio

freebsd/contrib/zstd/zlibWrapper/examples/example.c:139–218  ·  view source on GitHub ↗

=========================================================================== * Test read/write of .gz files */

(fname, uncompr, uncomprLen)

Source from the content-addressed store, hash-verified

137 * Test read/write of .gz files
138 */
139void test_gzio(fname, uncompr, uncomprLen)
140 const char *fname; /* compressed file name */
141 Byte *uncompr;
142 uLong uncomprLen;
143{
144#ifdef NO_GZCOMPRESS
145 fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n");
146#else
147 int err;
148 int len = (int)strlen(hello)+1;
149 gzFile file;
150 z_off_t pos;
151
152 file = gzopen(fname, "wb");
153 if (file == NULL) {
154 fprintf(stderr, "gzopen error\n");
155 exit(1);
156 }
157 gzputc(file, 'h');
158 if (gzputs(file, "ello") != 4) {
159 fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err));
160 exit(1);
161 }
162 if (gzprintf(file, ", %s! I said hello, hello!", "hello") != 8+21) {
163 fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err));
164 exit(1);
165 }
166 gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
167 gzclose(file);
168
169 file = gzopen(fname, "rb");
170 if (file == NULL) {
171 fprintf(stderr, "gzopen error\n");
172 exit(1);
173 }
174 strcpy((char*)uncompr, "garbage");
175
176 if (gzread(file, uncompr, (unsigned)uncomprLen) != len) {
177 fprintf(stderr, "gzread err: %s\n", gzerror(file, &err));
178 exit(1);
179 }
180 if (strcmp((char*)uncompr, hello)) {
181 fprintf(stderr, "bad gzread: %s\n", (char*)uncompr);
182 exit(1);
183 } else {
184 printf("gzread(): %s\n", (char*)uncompr);
185 }
186
187 pos = gzseek(file, -8L, SEEK_CUR);
188 if (pos != 6+21 || gztell(file) != pos) {
189 fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n",
190 (long)pos, (long)gztell(file));
191 exit(1);
192 }
193
194 if (gzgetc(file) != ' ') {
195 fprintf(stderr, "gzgetc error\n");
196 exit(1);

Callers 1

mainFunction · 0.70

Calls 12

strcmpFunction · 0.85
gzopenFunction · 0.70
gzcloseFunction · 0.70
gzreadFunction · 0.70
gzputcFunction · 0.50
gzputsFunction · 0.50
gzprintfFunction · 0.50
gzseekFunction · 0.50
printfFunction · 0.50
gztellFunction · 0.50
gzgetcFunction · 0.50
gzungetcFunction · 0.50

Tested by

no test coverage detected