Try compressing the input file at once using mmap. Return Z_OK if * if success, Z_ERRNO otherwise. */
(in, out)
| 398 | * if success, Z_ERRNO otherwise. |
| 399 | */ |
| 400 | int gz_compress_mmap(in, out) |
| 401 | FILE *in; |
| 402 | gzFile out; |
| 403 | { |
| 404 | int len; |
| 405 | int err; |
| 406 | int ifd = fileno(in); |
| 407 | caddr_t buf; /* mmap'ed buffer for the entire input file */ |
| 408 | off_t buf_len; /* length of the input file */ |
| 409 | struct stat sb; |
| 410 | |
| 411 | /* Determine the size of the file, needed for mmap: */ |
| 412 | if (fstat(ifd, &sb) < 0) return Z_ERRNO; |
| 413 | buf_len = sb.st_size; |
| 414 | if (buf_len <= 0) return Z_ERRNO; |
| 415 | |
| 416 | /* Now do the actual mmap: */ |
| 417 | buf = mmap((caddr_t) 0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0); |
| 418 | if (buf == (caddr_t)(-1)) return Z_ERRNO; |
| 419 | |
| 420 | /* Compress the whole file at once: */ |
| 421 | len = gzwrite(out, (char *)buf, (unsigned)buf_len); |
| 422 | |
| 423 | if (len != (int)buf_len) error(gzerror(out, &err)); |
| 424 | |
| 425 | munmap(buf, buf_len); |
| 426 | fclose(in); |
| 427 | if (gzclose(out) != Z_OK) error("failed gzclose"); |
| 428 | return Z_OK; |
| 429 | } |
| 430 | #endif /* USE_MMAP */ |
| 431 | |
| 432 | /* =========================================================================== |
no test coverage detected