Browse Source

Overwriting original file, if no output file were specified; closing files than they are no longer needed.

master
Golikov Ivan 6 years ago
parent
commit
9c8e592224
1 changed files with 7 additions and 0 deletions
  1. +7
    -0
      main.c

+ 7
- 0
main.c View File

@@ -78,13 +78,18 @@ int main(int argc, char *argv[]) {
}

struct image_data * original_image = decompress_image(infile);
fclose(infile);

if (original_image == NULL) {
fprintf(stderr, "Failed to decompress image %s\n", input_filename);
exit(1);
}

// If no output file were specified, use original image
FILE *outfile;
if (out_filename == NULL) {
out_filename = input_filename;
}

if ((outfile = fopen(out_filename, "wb")) == NULL) {
fprintf(stderr, "Can not open %s\n", out_filename);
@@ -128,6 +133,8 @@ int main(int argc, char *argv[]) {
int8_t compress_result;
compress_result = compress_image(blurred_image, outfile, 90);

fclose(outfile);

if (compress_result != 0) {
fprintf(stderr, "Failed to write blurred image to file!\n");



Loading…
Cancel
Save