David Malone wrote:

> I wonder if it would be better to use fwrite instead of write, to
> avoid mixing stdio and Posix-style output? (It would also avoid an
> unbuffered write of 1 byte.)

Good point.  How about the attached?

David
diff --git a/uip/post.c b/uip/post.c
index 820ed05b..a58e19a1 100644
--- a/uip/post.c
+++ b/uip/post.c
@@ -660 +660,3 @@ main (int argc, char **argv)
-	    case BODY: 
+	    case BODY: {
+		size_t n;
+
@@ -664 +666,9 @@ main (int argc, char **argv)
-		fprintf (out, "\n%s", buf);
+		if (fwrite ("\n", 1, 1, out) != 1) {
+		    adios ("write of newline between header and body", "failed");
+		}
+		/* Don't emit trailing NUL to avoid interfering with SMTP
+		   conversation. */
+		n =  bufsz >= 1 && buf[bufsz-1] == '\0' ? bufsz - 1 : bufsz;
+		if (fwrite (buf, 1, n, out) != n) {
+		    adios ("write of body", "failed");
+		}
@@ -668 +678,3 @@ main (int argc, char **argv)
-		    fputs (buf, out);
+		    if (fwrite (buf, 1, bufsz, out) != (size_t) bufsz) {
+			adios ("continued write of body", "failed");
+		    }
@@ -670,0 +683 @@ main (int argc, char **argv)
+	    }

Reply via email to