void gz_compress( FILE *in, gzFile out) { local char buf[BUFLEN]; int len; int err; #ifdef USE_MMAP /* Try first compressing with mmap. If mmap fails (minigzip used in a * pipe), use the normal fread loop. */ if (gz_compress_mmap(in, out) == Z_OK) return; #endif for (;;) { len = (int)fread(buf, 1, sizeof(buf), in); if (ferror(in)) { perror("fread"); exit(1); } if (len == 0) break; if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err)); } fclose(in); if (gzclose(out) != Z_OK) error("failed gzclose"); }
/* =========================================================================== * Compress input to output then close both files. */ BOOL gz_compress(FILE *lpInfile, gzFile lpOutfile) { BOOL nSuccess = TRUE; local char buf[BUFLEN]; INT32 len; int err; #ifdef USE_MMAP /* Try first compressing with mmap. If mmap fails (minigzip used in a * pipe), use the normal fread loop. */ if (gz_compress_mmap(lpInfile, lpOutfile) == Z_OK) return; #endif for (;;) { len = fread(buf, 1, sizeof(buf), lpInfile); if (ferror(lpInfile)) { perror("fread"); nSuccess = FALSE; } if (len == 0) break; if (gzwrite(lpOutfile, buf, (unsigned)len) != len) { perror(gzerror(lpOutfile, &err)); nSuccess = FALSE; } } fclose(lpInfile); if (gzclose(lpOutfile) != Z_OK) { perror("failed gzclose"); return nSuccess; } return TRUE; }