commit 15643f8f148616b3145c901fdf1ce307cbafb87f
parent 7f003863c128f9e19c9e13a9edb154982dbab912
Author: Paco Esteban <paco@e1e0.net>
Date: Wed, 24 Jun 2020 18:01:11 +0200
more error checking on fwrite and fclose functions
Diffstat:
2 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/helpers.c b/helpers.c
@@ -85,8 +85,10 @@ copy_file(const char *source_file, const char *dest_file, int force)
if (wcnt)
return ssnail_error_msg(2, "cp");
- fclose(src);
- fclose(dst);
+ if (fclose(src) != 0)
+ return ssnail_error_from_errno("close src");
+ if (fclose(dst) != 0)
+ return ssnail_error_from_errno("close dst");
}
return NULL;
diff --git a/ssnail.c b/ssnail.c
@@ -296,10 +296,20 @@ write_html(struct article *ap, char *head_tpl, char *foot_tpl)
error = ssnail_error_from_errno("openw dst_path");
goto out;
}
- fwrite(header, 1, strlen(header), fout);
- fwrite(ap->html_content, 1, ap->htmlz, fout);
- fwrite(footer, 1, strlen(footer), fout);
- fclose(fout);
+ if (fwrite(header, 1, strlen(header), fout) == 0) {
+ error = ssnail_error_from_errno("fwrite header");
+ goto out;
+ }
+ if (fwrite(ap->html_content, 1, ap->htmlz, fout) == 0) {
+ error = ssnail_error_from_errno("fwrite html content");
+ goto out;
+ }
+ if (fwrite(footer, 1, strlen(footer), fout) == 0) {
+ error = ssnail_error_from_errno("fwrite footer");
+ goto out;
+ }
+ if (fclose(fout) != 0)
+ error = ssnail_error_from_errno("close fout");
out:
free(header);