Bernhard Reutner-Fischer | c2cb0f3 | 2006-04-13 12:45:04 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 2 | /* |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 3 | * Copyright: Copyright (C) 2001, Hewlett-Packard Company |
| 4 | * Author: Christopher Hoover <ch@hpl.hp.com> |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 5 | * Description: xmodem functionality for uploading of kernels |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 6 | * and the like |
| 7 | * Created at: Thu Dec 20 01:58:08 PST 2001 |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 8 | * |
| 9 | * xmodem functionality for uploading of kernels and the like |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 10 | * |
| 11 | * Copyright (C) 2001 Hewlett-Packard Laboratories |
| 12 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 13 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 14 | * |
| 15 | * This was originally written for blob and then adapted for busybox. |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 18 | #include "libbb.h" |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 19 | |
| 20 | #define SOH 0x01 |
| 21 | #define STX 0x02 |
| 22 | #define EOT 0x04 |
| 23 | #define ACK 0x06 |
| 24 | #define NAK 0x15 |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 25 | #define BS 0x08 |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 26 | #define PAD 0x1A |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 27 | |
| 28 | /* |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 29 | Cf: |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 30 | http://www.textfiles.com/apple/xmodem |
| 31 | http://www.phys.washington.edu/~belonis/xmodem/docxmodem.txt |
| 32 | http://www.phys.washington.edu/~belonis/xmodem/docymodem.txt |
| 33 | http://www.phys.washington.edu/~belonis/xmodem/modmprot.col |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 34 | */ |
| 35 | |
| 36 | #define TIMEOUT 1 |
| 37 | #define TIMEOUT_LONG 10 |
| 38 | #define MAXERRORS 10 |
| 39 | |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 40 | #define read_fd STDIN_FILENO |
| 41 | #define write_fd STDOUT_FILENO |
| 42 | |
| 43 | static int read_byte(unsigned timeout) |
Denis Vlasenko | ac678ec | 2007-04-16 22:32:04 +0000 | [diff] [blame] | 44 | { |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 45 | unsigned char buf; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 46 | int n; |
| 47 | |
| 48 | alarm(timeout); |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 49 | /* NOT safe_read! We want ALRM to interrupt us */ |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 50 | n = read(read_fd, &buf, 1); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 51 | alarm(0); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 52 | if (n == 1) |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 53 | return buf; |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 54 | return -1; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 57 | static int receive(/*int read_fd, */int file_fd) |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 58 | { |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 59 | unsigned char blockBuf[1024]; |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 60 | unsigned blockLength = 0; |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 61 | unsigned errors = 0; |
| 62 | unsigned wantBlockNo = 1; |
| 63 | unsigned length = 0; |
| 64 | int do_crc = 1; |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 65 | char reply_char; |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 66 | unsigned timeout = TIMEOUT_LONG; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 67 | |
Rob Landley | 399d45f | 2006-06-21 01:49:17 +0000 | [diff] [blame] | 68 | /* Flush pending input */ |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 69 | tcflush(read_fd, TCIFLUSH); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 70 | |
| 71 | /* Ask for CRC; if we get errors, we will go with checksum */ |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 72 | reply_char = 'C'; |
| 73 | full_write(write_fd, &reply_char, 1); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 74 | |
| 75 | for (;;) { |
| 76 | int blockBegin; |
| 77 | int blockNo, blockNoOnesCompl; |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 78 | int cksum_or_crc; |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 79 | int expected; |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 80 | int i, j; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 81 | |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 82 | blockBegin = read_byte(timeout); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 83 | if (blockBegin < 0) |
| 84 | goto timeout; |
| 85 | |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 86 | /* If last block, remove padding */ |
| 87 | if (blockBegin == EOT) { |
| 88 | /* Data blocks can be padded with ^Z characters */ |
| 89 | /* This code tries to detect and remove them */ |
| 90 | if (blockLength >= 3 |
| 91 | && blockBuf[blockLength - 1] == PAD |
| 92 | && blockBuf[blockLength - 2] == PAD |
| 93 | && blockBuf[blockLength - 3] == PAD |
| 94 | ) { |
| 95 | while (blockLength |
| 96 | && blockBuf[blockLength - 1] == PAD |
| 97 | ) { |
| 98 | blockLength--; |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | /* Write previously received block */ |
| 103 | if (blockLength) { |
| 104 | errno = 0; |
| 105 | if (full_write(file_fd, blockBuf, blockLength) != blockLength) { |
| 106 | bb_perror_msg("can't write to file"); |
| 107 | goto fatal; |
| 108 | } |
| 109 | } |
| 110 | |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 111 | timeout = TIMEOUT; |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 112 | reply_char = NAK; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 113 | |
| 114 | switch (blockBegin) { |
| 115 | case SOH: |
| 116 | case STX: |
| 117 | break; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 118 | case EOT: |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 119 | reply_char = ACK; |
| 120 | full_write(write_fd, &reply_char, 1); |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 121 | return length; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 122 | default: |
| 123 | goto error; |
| 124 | } |
| 125 | |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 126 | /* Block no */ |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 127 | blockNo = read_byte(TIMEOUT); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 128 | if (blockNo < 0) |
| 129 | goto timeout; |
| 130 | |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 131 | /* Block no, in one's complement form */ |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 132 | blockNoOnesCompl = read_byte(TIMEOUT); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 133 | if (blockNoOnesCompl < 0) |
| 134 | goto timeout; |
| 135 | |
| 136 | if (blockNo != (255 - blockNoOnesCompl)) { |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 137 | bb_error_msg("bad block ones compl"); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 138 | goto error; |
| 139 | } |
| 140 | |
| 141 | blockLength = (blockBegin == SOH) ? 128 : 1024; |
| 142 | |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 143 | for (i = 0; i < blockLength; i++) { |
| 144 | int cc = read_byte(TIMEOUT); |
| 145 | if (cc < 0) |
| 146 | goto timeout; |
| 147 | blockBuf[i] = cc; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 150 | if (do_crc) { |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 151 | cksum_or_crc = read_byte(TIMEOUT); |
| 152 | if (cksum_or_crc < 0) |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 153 | goto timeout; |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 154 | cksum_or_crc = (cksum_or_crc << 8) | read_byte(TIMEOUT); |
| 155 | if (cksum_or_crc < 0) |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 156 | goto timeout; |
| 157 | } else { |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 158 | cksum_or_crc = read_byte(TIMEOUT); |
| 159 | if (cksum_or_crc < 0) |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 160 | goto timeout; |
| 161 | } |
| 162 | |
| 163 | if (blockNo == ((wantBlockNo - 1) & 0xff)) { |
| 164 | /* a repeat of the last block is ok, just ignore it. */ |
| 165 | /* this also ignores the initial block 0 which is */ |
| 166 | /* meta data. */ |
| 167 | goto next; |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 168 | } |
| 169 | if (blockNo != (wantBlockNo & 0xff)) { |
| 170 | bb_error_msg("unexpected block no, 0x%08x, expecting 0x%08x", blockNo, wantBlockNo); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 171 | goto error; |
| 172 | } |
| 173 | |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 174 | expected = 0; |
| 175 | if (do_crc) { |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 176 | for (i = 0; i < blockLength; i++) { |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 177 | expected = expected ^ blockBuf[i] << 8; |
| 178 | for (j = 0; j < 8; j++) { |
| 179 | if (expected & 0x8000) |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 180 | expected = (expected << 1) ^ 0x1021; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 181 | else |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 182 | expected = (expected << 1); |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 183 | } |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 184 | } |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 185 | expected &= 0xffff; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 186 | } else { |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 187 | for (i = 0; i < blockLength; i++) |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 188 | expected += blockBuf[i]; |
| 189 | expected &= 0xff; |
| 190 | } |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 191 | if (cksum_or_crc != expected) { |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 192 | bb_error_msg(do_crc ? "crc error, expected 0x%04x, got 0x%04x" |
| 193 | : "checksum error, expected 0x%02x, got 0x%02x", |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 194 | expected, cksum_or_crc); |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 195 | goto error; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | wantBlockNo++; |
| 199 | length += blockLength; |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 200 | next: |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 201 | errors = 0; |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 202 | reply_char = ACK; |
| 203 | full_write(write_fd, &reply_char, 1); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 204 | continue; |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 205 | error: |
| 206 | timeout: |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 207 | errors++; |
| 208 | if (errors == MAXERRORS) { |
| 209 | /* Abort */ |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 210 | |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 211 | /* If were asking for crc, try again w/o crc */ |
| 212 | if (reply_char == 'C') { |
| 213 | reply_char = NAK; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 214 | errors = 0; |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 215 | do_crc = 0; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 216 | goto timeout; |
| 217 | } |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 218 | bb_error_msg("too many errors; giving up"); |
| 219 | fatal: |
| 220 | /* 5 CAN followed by 5 BS. Don't try too hard... */ |
| 221 | safe_write(write_fd, "\030\030\030\030\030\010\010\010\010\010", 10); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 222 | return -1; |
| 223 | } |
| 224 | |
Rob Landley | 399d45f | 2006-06-21 01:49:17 +0000 | [diff] [blame] | 225 | /* Flush pending input */ |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 226 | tcflush(read_fd, TCIFLUSH); |
Rob Landley | 399d45f | 2006-06-21 01:49:17 +0000 | [diff] [blame] | 227 | |
Denys Vlasenko | dc9495d | 2009-08-02 19:45:31 +0200 | [diff] [blame] | 228 | full_write(write_fd, &reply_char, 1); |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 229 | } /* for (;;) */ |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 232 | static void sigalrm_handler(int UNUSED_PARAM signum) |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 233 | { |
| 234 | } |
| 235 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 236 | int rx_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denys Vlasenko | e992bae | 2009-11-28 15:18:53 +0100 | [diff] [blame] | 237 | int rx_main(int argc UNUSED_PARAM, char **argv) |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 238 | { |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 239 | struct termios tty, orig_tty; |
| 240 | int termios_err; |
| 241 | int file_fd; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 242 | int n; |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 243 | |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 244 | /* Disabled by vda: |
| 245 | * why we can't receive from stdin? Why we *require* |
| 246 | * controlling tty?? */ |
| 247 | /*read_fd = xopen(CURRENT_TTY, O_RDWR);*/ |
Denys Vlasenko | e992bae | 2009-11-28 15:18:53 +0100 | [diff] [blame] | 248 | file_fd = xopen(single_argv(argv), O_RDWR|O_CREAT|O_TRUNC); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 249 | |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 250 | termios_err = tcgetattr(read_fd, &tty); |
| 251 | if (termios_err == 0) { |
| 252 | orig_tty = tty; |
| 253 | cfmakeraw(&tty); |
| 254 | tcsetattr(read_fd, TCSAFLUSH, &tty); |
| 255 | } |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 256 | |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 257 | /* No SA_RESTART: we want ALRM to interrupt read() */ |
Denis Vlasenko | 8e2cfec | 2008-03-12 23:19:35 +0000 | [diff] [blame] | 258 | signal_no_SA_RESTART_empty_mask(SIGALRM, sigalrm_handler); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 259 | |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 260 | n = receive(file_fd); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 261 | |
Denis Vlasenko | 4cf1d08 | 2008-03-12 23:13:50 +0000 | [diff] [blame] | 262 | if (termios_err == 0) |
| 263 | tcsetattr(read_fd, TCSAFLUSH, &orig_tty); |
| 264 | if (ENABLE_FEATURE_CLEAN_UP) |
| 265 | close(file_fd); |
| 266 | fflush_stdout_and_exit(n >= 0); |
Glenn L McGrath | 8f3bc4c | 2003-12-20 07:30:35 +0000 | [diff] [blame] | 267 | } |