Browse code

Handle partial writes - and print when write fails

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@239 77e5149b-7576-45b1-b177-96237e5ba77b

Nigel Horne authored on 2004/02/04 22:29:48
Showing 1 changed files
... ...
@@ -17,6 +17,9 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: mbox.c,v $
20
+ * Revision 1.38  2004/02/04 13:29:48  nigelhorne
21
+ * Handle partial writes - and print when write fails
22
+ *
20 23
  * Revision 1.37  2004/02/03 22:54:59  nigelhorne
21 24
  * Catch another example of Worm.Dumaru.Y
22 25
  *
... ...
@@ -102,7 +105,7 @@
102 102
  * Compilable under SCO; removed duplicate code with message.c
103 103
  *
104 104
  */
105
-static	char	const	rcsid[] = "$Id: mbox.c,v 1.37 2004/02/03 22:54:59 nigelhorne Exp $";
105
+static	char	const	rcsid[] = "$Id: mbox.c,v 1.38 2004/02/04 13:29:48 nigelhorne Exp $";
106 106
 
107 107
 #ifndef	CL_DEBUG
108 108
 /*#define	NDEBUG	/* map CLAMAV debug onto standard */
... ...
@@ -1596,6 +1599,7 @@ saveFile(const blob *b, const char *dir)
1596 1596
 	size_t len = 0;
1597 1597
 	int fd;
1598 1598
 	const char *cptr, *suffix;
1599
+	unsigned char *data;
1599 1600
 	char filename[NAME_MAX + 1];
1600 1601
 
1601 1602
 	assert(dir != NULL);
... ...
@@ -1660,9 +1664,20 @@ saveFile(const blob *b, const char *dir)
1660 1660
 #endif
1661 1661
 	}
1662 1662
 
1663
-	write(fd, blobGetData(b), (size_t)nbytes);
1664
-	cli_dbgmsg("Attachment saved as %s (%lu bytes long)\n",
1663
+	cli_dbgmsg("Saving attachment as %s (%lu bytes long)\n",
1665 1664
 		filename, nbytes);
1666 1665
 
1666
+	data = blobGetData(b);
1667
+	while(nbytes > 0) {
1668
+		int rc = write(fd, data, (size_t)nbytes);
1669
+		if(rc < 0) {
1670
+			perror(filename);
1671
+			close(fd);
1672
+			return FALSE;
1673
+		}
1674
+		nbytes -= rc;
1675
+		data = &data[rc];
1676
+	}
1677
+
1667 1678
 	return (close(fd) >= 0);
1668 1679
 }