=========================================================================== * Uncompress the given file and remove the original. */
(file)
| 495 | * Uncompress the given file and remove the original. |
| 496 | */ |
| 497 | void file_uncompress(file) |
| 498 | char *file; |
| 499 | { |
| 500 | local char buf[MAX_NAME_LEN]; |
| 501 | char *infile, *outfile; |
| 502 | FILE *out; |
| 503 | gzFile in; |
| 504 | size_t len = strlen(file); |
| 505 | |
| 506 | if (len + strlen(GZ_SUFFIX) >= sizeof(buf)) { |
| 507 | fprintf(stderr, "%s: filename too long\n", prog); |
| 508 | exit(1); |
| 509 | } |
| 510 | |
| 511 | strcpy(buf, file); |
| 512 | |
| 513 | if (len > SUFFIX_LEN && strcmp(file+len-SUFFIX_LEN, GZ_SUFFIX) == 0) { |
| 514 | infile = file; |
| 515 | outfile = buf; |
| 516 | outfile[len-3] = '\0'; |
| 517 | } else { |
| 518 | outfile = file; |
| 519 | infile = buf; |
| 520 | strcat(infile, GZ_SUFFIX); |
| 521 | } |
| 522 | in = gzopen(infile, "rb"); |
| 523 | if (in == NULL) { |
| 524 | fprintf(stderr, "%s: can't gzopen %s\n", prog, infile); |
| 525 | exit(1); |
| 526 | } |
| 527 | out = fopen(outfile, "wb"); |
| 528 | if (out == NULL) { |
| 529 | perror(file); |
| 530 | exit(1); |
| 531 | } |
| 532 | |
| 533 | gz_uncompress(in, out); |
| 534 | |
| 535 | unlink(infile); |
| 536 | } |
| 537 | |
| 538 | |
| 539 | /* =========================================================================== |
no test coverage detected