+
+ /* Flush the buffer and rewind to beginning - to read and save into
+ gzip compressed file */
+ fflush (outfile);
+ fseek (outfile, 0, 0);
+
+ /* now compress the file and save it to destination file */
+ gzFile outdestfile = gzopen (file, "wb");
+ if (outdestfile == NULL)
+ {
+ fprintf (stderr, "%s\n", ERROR_WRITING_FILE);
+ fclose (outfile);
+ exit (1);
+ }
+ char buf[128];
+ int num = fread (buf, sizeof(char), sizeof(char)*128, outfile);
+ while (num > 0)
+ {
+ int res = gzwrite (outdestfile, buf, num*sizeof(char) );
+ if (res == 0)
+ {
+ fprintf (stderr, "%s %s\n", ERROR_WRITING_FILE, COMPRESSED);
+ fclose (outfile);
+ exit (1);
+ }
+ num = fread (buf, sizeof(char), sizeof(char)*128, outfile);
+ }
+ gzclose (outdestfile);