(in, out)
| 360 | */ |
| 361 | |
| 362 | void gz_compress(in, out) |
| 363 | FILE *in; |
| 364 | gzFile out; |
| 365 | { |
| 366 | local char buf[BUFLEN]; |
| 367 | int len; |
| 368 | int err; |
| 369 | |
| 370 | #ifdef USE_MMAP |
| 371 | /* Try first compressing with mmap. If mmap fails (minigzip used in a |
| 372 | * pipe), use the normal fread loop. |
| 373 | */ |
| 374 | if (gz_compress_mmap(in, out) == Z_OK) return; |
| 375 | #endif |
| 376 | for (;;) { |
| 377 | len = (int)fread(buf, 1, sizeof(buf), in); |
| 378 | if (ferror(in)) { |
| 379 | perror("fread"); |
| 380 | exit(1); |
| 381 | } |
| 382 | if (len == 0) break; |
| 383 | |
| 384 | if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err)); |
| 385 | } |
| 386 | fclose(in); |
| 387 | if (gzclose(out) != Z_OK) error("failed gzclose"); |
| 388 | } |
| 389 | |
| 390 | #ifdef USE_MMAP /* MMAP version, Miguel Albrecht <malbrech@eso.org> */ |
| 391 |
no test coverage detected