Index: testing/cmd_1.c
===================================================================
RCS file: /var/cvs/comedilib/testing/cmd_1.c,v
retrieving revision 1.11
diff -u -r1.11 cmd_1.c
--- testing/cmd_1.c	25 Jul 2004 00:39:39 -0000	1.11
+++ testing/cmd_1.c	23 Feb 2005 16:12:38 -0000
@@ -163,6 +163,7 @@
 	unsigned int flags = comedi_get_subdevice_flags(device,subdevice);
 	static const int num_samples = 100000;
 	int num_bytes;
+	int wc;
 	
 	if((flags & SDF_LSAMPL))
 	{
@@ -197,14 +198,17 @@
 
 	go = 1;
 	while(go){
-		ret = write(comedi_fileno(device), buf, BUFSZ);
+		wc = num_bytes-total;
+		if(wc>BUFSZ){
+			wc = BUFSZ;
+		}
+		ret = write(comedi_fileno(device), buf, wc);
 		if(ret<0){
 			perror("write");
 			return 0;
 		}
-		if(ret<BUFSZ){
+		if(ret<wc){
 			go = 0;
-			break;
 		}
 
 		total += ret;
@@ -219,9 +223,13 @@
 	}
 	if(verbose)printf("inttrig\n");
 
-	go=1;
+	go=(total<num_bytes);
 	while(go){
-		ret = write(comedi_fileno(device),buf,BUFSZ);
+		wc = num_bytes-total;
+		if(wc>BUFSZ){
+			wc = BUFSZ;
+		}
+		ret = write(comedi_fileno(device),buf,wc);
 		if(ret<0){
 			if(errno==EAGAIN){
 				usleep(10000);

