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

Function test_gzio

freebsd/contrib/zstd/zlibWrapper/examples/example_original.c:131–210  ·  view source on GitHub ↗

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

(fname, uncompr, uncomprLen)

Source from the content-addressed store, hash-verified

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