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

Function file_uncompress

freebsd/contrib/zstd/zlibWrapper/examples/minigzip.c:497–536  ·  view source on GitHub ↗

=========================================================================== * Uncompress the given file and remove the original. */

(file)

Source from the content-addressed store, hash-verified

495 * Uncompress the given file and remove the original.
496 */
497void 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/* ===========================================================================

Callers 1

mainFunction · 0.70

Calls 4

strcmpFunction · 0.85
strcatFunction · 0.85
gzopenFunction · 0.70
gz_uncompressFunction · 0.70

Tested by

no test coverage detected