Issue 695: check fwrite return value, sync up test harnesses
diff --git a/cat/test/main.c b/cat/test/main.c
index 8c414da..319f68c 100644
--- a/cat/test/main.c
+++ b/cat/test/main.c
@@ -780,6 +780,34 @@
 	return (0);
 }
 
+/* Verify that a block of memory is filled with the specified byte. */
+int
+assertion_memory_filled_with(const char *file, int line,
+    const void *_v1, const char *vd,
+    size_t l, const char *ld,
+    char b, const char *bd, void *extra)
+{
+	const char *v1 = (const char *)_v1;
+	size_t c = 0;
+	size_t i;
+	(void)ld; /* UNUSED */
+
+	assertion_count(file, line);
+
+	for (i = 0; i < l; ++i) {
+		if (v1[i] == b) {
+			++c;
+		}
+	}
+	if (c == l)
+		return (1);
+
+	failure_start(file, line, "%s (size %d) not filled with %s", vd, (int)l, bd);
+	logprintf("   Only %d bytes were correct\n", (int)c);
+	failure_finish(extra);
+	return (0);
+}
+
 /* Verify that the named file exists and is empty. */
 int
 assertion_empty_file(const char *filename, int line, const char *f1)
@@ -2276,7 +2304,10 @@
 	/* Not a lot of error checking here; the input better be right. */
 	out = fopen(name, "wb");
 	while ((rbytes = fread(buff, 1, sizeof(buff), in)) > 0) {
-		fwrite(buff, 1, rbytes, out);
+		if (fwrite(buff, 1, rbytes, out) != rbytes) {
+			logprintf("Error: fwrite\n");
+			break;
+		}
 	}
 	fclose(out);
 	fclose(in);
diff --git a/cpio/test/main.c b/cpio/test/main.c
index 5801127..fa22adf 100644
--- a/cpio/test/main.c
+++ b/cpio/test/main.c
@@ -781,6 +781,34 @@
 	return (0);
 }
 
+/* Verify that a block of memory is filled with the specified byte. */
+int
+assertion_memory_filled_with(const char *file, int line,
+    const void *_v1, const char *vd,
+    size_t l, const char *ld,
+    char b, const char *bd, void *extra)
+{
+	const char *v1 = (const char *)_v1;
+	size_t c = 0;
+	size_t i;
+	(void)ld; /* UNUSED */
+
+	assertion_count(file, line);
+
+	for (i = 0; i < l; ++i) {
+		if (v1[i] == b) {
+			++c;
+		}
+	}
+	if (c == l)
+		return (1);
+
+	failure_start(file, line, "%s (size %d) not filled with %s", vd, (int)l, bd);
+	logprintf("   Only %d bytes were correct\n", (int)c);
+	failure_finish(extra);
+	return (0);
+}
+
 /* Verify that the named file exists and is empty. */
 int
 assertion_empty_file(const char *filename, int line, const char *f1)
@@ -2277,7 +2305,10 @@
 	/* Not a lot of error checking here; the input better be right. */
 	out = fopen(name, "wb");
 	while ((rbytes = fread(buff, 1, sizeof(buff), in)) > 0) {
-		fwrite(buff, 1, rbytes, out);
+		if (fwrite(buff, 1, rbytes, out) != rbytes) {
+			logprintf("Error: fwrite\n");
+			break;
+		}
 	}
 	fclose(out);
 	fclose(in);
diff --git a/libarchive/test/main.c b/libarchive/test/main.c
index 8561129..e0af431 100644
--- a/libarchive/test/main.c
+++ b/libarchive/test/main.c
@@ -2303,7 +2303,10 @@
 	/* Not a lot of error checking here; the input better be right. */
 	out = fopen(name, "wb");
 	while ((rbytes = fread(buff, 1, sizeof(buff), in)) > 0) {
-		fwrite(buff, 1, rbytes, out);
+		if (fwrite(buff, 1, rbytes, out) != rbytes) {
+			logprintf("Error: fwrite\n");
+			break;
+		}
 	}
 	fclose(out);
 	fclose(in);
diff --git a/tar/test/main.c b/tar/test/main.c
index 33a6364..90801a9 100644
--- a/tar/test/main.c
+++ b/tar/test/main.c
@@ -781,6 +781,34 @@
 	return (0);
 }
 
+/* Verify that a block of memory is filled with the specified byte. */
+int
+assertion_memory_filled_with(const char *file, int line,
+    const void *_v1, const char *vd,
+    size_t l, const char *ld,
+    char b, const char *bd, void *extra)
+{
+	const char *v1 = (const char *)_v1;
+	size_t c = 0;
+	size_t i;
+	(void)ld; /* UNUSED */
+
+	assertion_count(file, line);
+
+	for (i = 0; i < l; ++i) {
+		if (v1[i] == b) {
+			++c;
+		}
+	}
+	if (c == l)
+		return (1);
+
+	failure_start(file, line, "%s (size %d) not filled with %s", vd, (int)l, bd);
+	logprintf("   Only %d bytes were correct\n", (int)c);
+	failure_finish(extra);
+	return (0);
+}
+
 /* Verify that the named file exists and is empty. */
 int
 assertion_empty_file(const char *filename, int line, const char *f1)
@@ -2277,7 +2305,10 @@
 	/* Not a lot of error checking here; the input better be right. */
 	out = fopen(name, "wb");
 	while ((rbytes = fread(buff, 1, sizeof(buff), in)) > 0) {
-		fwrite(buff, 1, rbytes, out);
+		if (fwrite(buff, 1, rbytes, out) != rbytes) {
+			logprintf("Error: fwrite\n");
+			break;
+		}
 	}
 	fclose(out);
 	fclose(in);