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

Function file_compress

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

=========================================================================== * Compress the given file: create a corresponding .gz file and remove the * original. */

(file, mode)

Source from the content-addressed store, hash-verified

460 * original.
461 */
462void file_compress(file, mode)
463 char *file;
464 char *mode;
465{
466 local char outfile[MAX_NAME_LEN];
467 FILE *in;
468 gzFile out;
469
470 if (strlen(file) + strlen(GZ_SUFFIX) >= sizeof(outfile)) {
471 fprintf(stderr, "%s: filename too long\n", prog);
472 exit(1);
473 }
474
475 strcpy(outfile, file);
476 strcat(outfile, GZ_SUFFIX);
477
478 in = fopen(file, "rb");
479 if (in == NULL) {
480 perror(file);
481 exit(1);
482 }
483 out = gzopen(outfile, mode);
484 if (out == NULL) {
485 fprintf(stderr, "%s: can't gzopen %s\n", prog, outfile);
486 exit(1);
487 }
488 gz_compress(in, out);
489
490 unlink(file);
491}
492
493
494/* ===========================================================================

Callers 1

mainFunction · 0.70

Calls 3

strcatFunction · 0.85
gzopenFunction · 0.70
gz_compressFunction · 0.70

Tested by

no test coverage detected