res = write(fd, buf, MAIL_LEN);
if (res < MAIL_LEN) {
unlink(b->tmpfile);
- bye(EX_TEMPFAIL, "Cannot write to remporary file: %m");
+ bye(EX_TEMPFAIL, "Cannot write to temporary file: %m");
}
break;
}
write_email_to_fd(int fd, struct email* email)
{
char* buf;
- int wr;
+ int wr, to_write;
open_email();
- do {
+ for (;;) {
buf = read_email(email);
- wr = write(fd, buf, chars_written);
- if (wr < chars_written)
- return 1;
- } while (chars_written);
+ if (!chars_written)
+ break;
+
+ to_write = chars_written;
+ while (to_write) {
+ wr = write(fd, buf, to_write);
+ to_write -= wr;
+ }
+ };
return 0;
}