X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=miscutils%2Frx.c;h=874a3f0a33a5667abbaef568212bd1161bb68d02;hb=363fb5ec4091120003b3f204996e7ff0aa354e58;hp=972f7ff37c0cf67b8e953efc0130cdf2ba40ca4b;hpb=f808e777db05bed7b3c0a4aa5f12121fb3d0ca5f;p=oweals%2Fbusybox.git diff --git a/miscutils/rx.c b/miscutils/rx.c index 972f7ff37..874a3f0a3 100644 --- a/miscutils/rx.c +++ b/miscutils/rx.c @@ -14,6 +14,16 @@ * * This was originally written for blob and then adapted for busybox. */ +//config:config RX +//config: bool "rx (2.9 kb)" +//config: default y +//config: select PLATFORM_LINUX +//config: help +//config: Receive files using the Xmodem protocol. + +//applet:IF_RX(APPLET(rx, BB_DIR_USR_BIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_RX) += rx.o //usage:#define rx_trivial_usage //usage: "FILE" @@ -84,7 +94,7 @@ static int receive(/*int read_fd, */int file_fd) int blockBegin; int blockNo, blockNoOnesCompl; int cksum_or_crc; - int expected; + unsigned expected; int i, j; blockBegin = read_byte(timeout); @@ -101,19 +111,17 @@ static int receive(/*int read_fd, */int file_fd) && blockBuf[blockLength - 3] == PAD ) { while (blockLength - && blockBuf[blockLength - 1] == PAD + && blockBuf[blockLength - 1] == PAD ) { blockLength--; } } } /* Write previously received block */ - if (blockLength) { - errno = 0; - if (full_write(file_fd, blockBuf, blockLength) != blockLength) { - bb_perror_msg("can't write to file"); - goto fatal; - } + errno = 0; + if (full_write(file_fd, blockBuf, blockLength) != blockLength) { + bb_perror_msg(bb_msg_write_error); + goto fatal; } timeout = TIMEOUT; @@ -155,17 +163,13 @@ static int receive(/*int read_fd, */int file_fd) blockBuf[i] = cc; } + cksum_or_crc = read_byte(TIMEOUT); + if (cksum_or_crc < 0) + goto timeout; if (do_crc) { - cksum_or_crc = read_byte(TIMEOUT); - if (cksum_or_crc < 0) - goto timeout; cksum_or_crc = (cksum_or_crc << 8) | read_byte(TIMEOUT); if (cksum_or_crc < 0) goto timeout; - } else { - cksum_or_crc = read_byte(TIMEOUT); - if (cksum_or_crc < 0) - goto timeout; } if (blockNo == ((wantBlockNo - 1) & 0xff)) { @@ -199,8 +203,8 @@ static int receive(/*int read_fd, */int file_fd) } if (cksum_or_crc != expected) { bb_error_msg(do_crc ? "crc error, expected 0x%04x, got 0x%04x" - : "checksum error, expected 0x%02x, got 0x%02x", - expected, cksum_or_crc); + : "checksum error, expected 0x%02x, got 0x%02x", + expected, cksum_or_crc); goto error; } @@ -213,6 +217,7 @@ static int receive(/*int read_fd, */int file_fd) continue; error: timeout: + blockLength = 0; errors++; if (errors == MAXERRORS) { /* Abort */ @@ -258,6 +263,7 @@ int rx_main(int argc UNUSED_PARAM, char **argv) termios_err = tcgetattr(read_fd, &tty); if (termios_err == 0) { +//TODO: use set_termios_to_raw() orig_tty = tty; cfmakeraw(&tty); tcsetattr(read_fd, TCSAFLUSH, &tty);