Browse code

add writen() function for wrapping write()

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

Trog authored on 2004/04/01 19:26:42
Showing 4 changed files
... ...
@@ -1,3 +1,7 @@
1
+Thu Apr  1 11:37:25 BST 2004 (trog)
2
+-----------------------------------
3
+  * clamd: add writen() function for wrapping write()
4
+
1 5
 Wed Mar 31 22:00:05 BST 2004 (njh)
2 6
 ----------------------------------
3 7
   * clamav-milter:	Handle new location of config file parser
... ...
@@ -22,6 +26,7 @@ Tue Mar 30 23:18:49 CEST 2004 (tk)
22 22
 Tue Mar 30 08:40:10 BST 2004 (trog)
23 23
 -----------------------------------
24 24
   * clamav.conf, shared/cfgparser.c: recognise ReadTimeout option
25
+	remove ThreadTimeout option
25 26
 
26 27
 Mon Mar 29 18:11:08 CEST 2004 (tk)
27 28
 ----------------------------------
... ...
@@ -182,3 +182,30 @@ int is_fd_connected(int fd)
182 182
     return 1;
183 183
 #endif
184 184
 }
185
+
186
+/* Function: writen
187
+	Try hard to write the specified number of bytes
188
+*/
189
+int writen(int fd, void *buff, unsigned int count)
190
+{
191
+	int retval;
192
+	unsigned int todo;
193
+	unsigned char *current;
194
+ 
195
+    todo = count;
196
+    current = (unsigned char *) buff;
197
+ 
198
+    do {
199
+	retval = write(fd, current, todo);
200
+	if (retval < 0) {
201
+	    if (errno == EINTR) {
202
+		continue;
203
+	    }
204
+	    return -1;
205
+	}
206
+	todo -= retval;
207
+	current += retval;
208
+    } while (todo > 0);
209
+ 
210
+    return count;
211
+}
... ...
@@ -30,5 +30,6 @@
30 30
 int poll_fd(int fd, int timeout_sec);
31 31
 int is_fd_connected(int fd);
32 32
 void virusaction(const char *filename, const char *virname, const struct cfgstruct *copt);
33
+int writen(int fd, void *buff, unsigned int count);
33 34
 
34 35
 #endif
... ...
@@ -295,7 +295,7 @@ int scanstream(int odesc, unsigned long int *scanned, const struct cl_node *root
295 295
 		return -1;
296 296
 	    }
297 297
 
298
-	    if(write(tmpd, buff, bread) < 0) {
298
+	    if(writen(tmpd, buff, bread) != bread) {
299 299
 		shutdown(sockfd, 2);
300 300
 		close(sockfd);
301 301
 		close(acceptd);