From 9e6dc28ab3c023269476ee8253e76f1efb919fcc Mon Sep 17 00:00:00 2001 From: Bruce Evans Date: Sun, 16 Apr 1995 22:40:49 +0000 Subject: [PATCH] Check for i/o errors in fclose() so that a full disk doesn't almost guarantee truncation of the file being edited. --- usr.sbin/ctm/ctm/ctm_ed.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/usr.sbin/ctm/ctm/ctm_ed.c b/usr.sbin/ctm/ctm/ctm_ed.c index 219fafca31ac..4fdf3b9ba6aa 100644 --- a/usr.sbin/ctm/ctm/ctm_ed.c +++ b/usr.sbin/ctm/ctm/ctm_ed.c @@ -6,7 +6,7 @@ * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * - * $Id$ + * $Id: ctm_ed.c,v 1.4 1994/09/22 02:49:17 phk Exp $ * */ @@ -92,12 +92,23 @@ ctm_edit(u_char *script, int length, char *filein, char *fileout) if(c == EOF) break; putc(c,fo); } - fclose(fi); - fclose(fo); - return 0; + ret = 0; bye: - if(fi) fclose(fi); - if(fo) fclose(fo); + if(fi) { + if(fclose(fi) != 0) { + perror(filein); + ret = 1; + } + } + if(fo) { + if(fflush(fo) != 0) { + perror(fileout); + ret = 1; + } + if(fclose(fo) != 0) { + perror(fileout); + ret = 1; + } + } return ret; } -