Current-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: CVS commit: src/usr.bin/patch
Thanks for the comments - a very good point about fputs perhaps
succeeding when just writing to the buffer.
It turns out this is trickier, because the file is closed in multiple
places and patch defined away the return value to not catch these errors
:-(
The treatment is fatal, not warning - it's really not ok to exit with
status 0 and incorrect output.
The following patch is relative to patch from before my recent change;
my intent is to commit both this and the reversion of the addition of
safe_fputs. Comments?
Index: common.h
===================================================================
RCS file: /cvsroot/src/usr.bin/patch/common.h,v
retrieving revision 1.18
diff -u -p -r1.18 common.h
--- common.h 14 Oct 2007 04:54:34 -0000 1.18
+++ common.h 15 Aug 2008 15:05:31 -0000
@@ -33,7 +33,11 @@
#define Fstat (void)fstat
#define Pclose (void)pclose
#define Close (void)close
-#define Fclose (void)fclose
+/*
+ * Pay attention to fclose, because otherwise patch happily truncates
+ * output files.
+ */
+#define Fclose /*(void)*/fclose
#define Fflush (void)fflush
#include <stdio.h>
Index: patch.c
===================================================================
RCS file: /cvsroot/src/usr.bin/patch/patch.c,v
retrieving revision 1.25
diff -u -p -r1.25 patch.c
--- patch.c 14 Oct 2007 04:54:34 -0000 1.25
+++ patch.c 15 Aug 2008 15:05:31 -0000
@@ -240,7 +240,8 @@ main(int argc, char *argv[])
++fuzz <= mymaxfuzz);
if (skip_rest_of_patch) { /* just got decided */
- Fclose(ofp);
+ if(Fclose(ofp) != 0)
+ pfatal("closing output file: %s", strerror(errno));
ofp = NULL;
}
}
@@ -299,7 +300,8 @@ main(int argc, char *argv[])
while (unlink(realout) >= 0) ; /* while is for Eunice. */
}
}
- Fclose(rejfp);
+ if(Fclose(rejfp) != 0)
+ pfatal("closing output file: %s", strerror(errno));
rejfp = NULL;
if (failed) {
failtotal += failed;
@@ -845,7 +847,8 @@ spew_output(void)
#endif
if (input_lines)
copy_till(input_lines); /* dump remainder of file */
- Fclose(ofp);
+ if (Fclose(ofp) != 0)
+ pfatal("closing output file: %s", strerror(errno));
ofp = NULL;
}
Index: pch.c
===================================================================
RCS file: /cvsroot/src/usr.bin/patch/pch.c,v
retrieving revision 1.22
diff -u -p -r1.22 pch.c
--- pch.c 26 Sep 2006 16:36:07 -0000 1.22
+++ pch.c 15 Aug 2008 15:05:31 -0000
@@ -88,7 +88,8 @@ open_patch_file(char *filename)
pfatal("can't create %s", TMPPATNAME);
while (fgets(buf, sizeof buf, stdin) != NULL)
fputs(buf, pfp);
- Fclose(pfp);
+ if (Fclose(pfp) != 0)
+ pfatal("closing output file: %s", strerror(errno));
filename = TMPPATNAME;
}
pfp = fopen(filename, "r");
Home |
Main Index |
Thread Index |
Old Index