svn commit: trunk/busybox/miscutils

landley at busybox.net landley at busybox.net
Wed Jun 21 01:49:20 UTC 2006


Author: landley
Date: 2006-06-20 18:49:17 -0700 (Tue, 20 Jun 2006)
New Revision: 15453

Log:
Aurelien Jacobs pointed out inline functions that could be removed.  Doing so
shrank the code a bit.


Modified:
   trunk/busybox/miscutils/rx.c


Changeset:
Modified: trunk/busybox/miscutils/rx.c
===================================================================
--- trunk/busybox/miscutils/rx.c	2006-06-21 01:15:36 UTC (rev 15452)
+++ trunk/busybox/miscutils/rx.c	2006-06-21 01:49:17 UTC (rev 15453)
@@ -39,7 +39,6 @@
 #define EOT 0x04
 #define ACK 0x06
 #define NAK 0x15
-#define CAN 0x18
 #define BS  0x08
 
 /*
@@ -57,18 +56,6 @@
 #define TIMEOUT_LONG 10
 #define MAXERRORS 10
 
-static inline void write_byte(int fd, char cc) {
-	write(fd, &cc, 1);
-}
-
-static inline void write_flush(int fd) {
-	tcdrain(fd);
-}
-
-static inline void read_flush(int fd) {
-	tcflush(fd, TCIFLUSH);
-}
-
 static int read_byte(int fd, unsigned int timeout) {
 	char buf[1];
 	int n;
@@ -99,11 +86,11 @@
 #define note_error(fmt,args...) \
 	snprintf(error_buf, error_buf_size, fmt,##args)
 
-	read_flush(ttyfd);
+	/* Flush pending input */
+	tcflush(ttyfd, TCIFLUSH);
 
 	/* Ask for CRC; if we get errors, we will go with checksum */
-	write_byte(ttyfd, nak);
-	write_flush(ttyfd);
+	write(ttyfd, &nak, 1);
 
 	for (;;) {
 		int blockBegin;
@@ -126,8 +113,8 @@
 			break;
 
 		case EOT:
-			write_byte(ttyfd, ACK);
-			write_flush(ttyfd);
+			nak = ACK;
+			write(ttyfd, &nak, 1);
 			goto done;
 
 		default:
@@ -232,8 +219,8 @@
 
 	next:
 		errors = 0;
-		write_byte(ttyfd, ACK);
-		write_flush(ttyfd);
+		nak = ACK;
+		write(ttyfd, &nak, 1);
 		continue;
 
 	error:
@@ -241,7 +228,6 @@
 		errors++;
 		if (errors == MAXERRORS) {
 			/* Abort */
-			int i;
 
 			// if using crc, try again w/o crc
 			if (nak == 'C') {
@@ -254,17 +240,15 @@
 			note_error("too many errors; giving up");
 
 		fatal:
-			for (i = 0; i < 5; i ++)
-				write_byte(ttyfd, CAN);
-			for (i = 0; i < 5; i ++)
-				write_byte(ttyfd, BS);
-			write_flush(ttyfd);
+			/* 5 CAN followed by 5 BS */
+			write(ttyfd, "\030\030\030\030\030\010\010\010\010\010", 10);
 			return -1;
 		}
 
-		read_flush(ttyfd);
-		write_byte(ttyfd, nak);
-		write_flush(ttyfd);
+		/* Flush pending input */
+		tcflush(ttyfd, TCIFLUSH);
+
+		write(ttyfd, &nak, 1);
 	}
 
  done:




More information about the busybox-cvs mailing list