"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 2 | #include "libbb.h" |
| 3 | |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 4 | /* uncompress for busybox -- (c) 2002 Robert Griebl |
| 5 | * |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 6 | * based on the original compress42.c source |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 7 | * (see disclaimer below) |
| 8 | */ |
| 9 | |
| 10 | |
| 11 | /* (N)compress42.c - File compression ala IEEE Computer, Mar 1992. |
| 12 | * |
| 13 | * Authors: |
| 14 | * Spencer W. Thomas (decvax!harpo!utah-cs!utah-gr!thomas) |
| 15 | * Jim McKie (decvax!mcvax!jim) |
| 16 | * Steve Davies (decvax!vax135!petsd!peora!srd) |
| 17 | * Ken Turkowski (decvax!decwrl!turtlevax!ken) |
| 18 | * James A. Woods (decvax!ihnp4!ames!jaw) |
| 19 | * Joe Orost (decvax!vax135!petsd!joe) |
| 20 | * Dave Mack (csu@alembic.acs.com) |
| 21 | * Peter Jannesen, Network Communication Systems |
| 22 | * (peter@ncs.nl) |
| 23 | * |
| 24 | * marc@suse.de : a small security fix for a buffer overflow |
| 25 | * |
| 26 | * [... History snipped ...] |
| 27 | * |
| 28 | */ |
Glenn L McGrath | 2e41d0c | 2002-09-27 06:46:02 +0000 | [diff] [blame] | 29 | #include <stdio.h> |
| 30 | #include <string.h> |
| 31 | #include <unistd.h> |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 32 | |
Eric Andersen | aff114c | 2004-04-14 17:51:38 +0000 | [diff] [blame] | 33 | /* Default input buffer size */ |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 34 | #define IBUFSIZ 2048 |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 35 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 36 | /* Default output buffer size */ |
| 37 | #define OBUFSIZ 2048 |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 38 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 39 | /* Defines for third byte of header */ |
| 40 | #define MAGIC_1 (char_type)'\037' /* First byte of compressed file */ |
| 41 | #define MAGIC_2 (char_type)'\235' /* Second byte of compressed file */ |
| 42 | #define BIT_MASK 0x1f /* Mask for 'number of compresssion bits' */ |
| 43 | /* Masks 0x20 and 0x40 are free. */ |
| 44 | /* I think 0x20 should mean that there is */ |
| 45 | /* a fourth header byte (for expansion). */ |
| 46 | #define BLOCK_MODE 0x80 /* Block compresssion if table is full and */ |
| 47 | /* compression rate is dropping flush tables */ |
| 48 | /* the next two codes should not be changed lightly, as they must not */ |
| 49 | /* lie within the contiguous general code space. */ |
| 50 | #define FIRST 257 /* first free entry */ |
| 51 | #define CLEAR 256 /* table clear output code */ |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 52 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 53 | #define INIT_BITS 9 /* initial number of bits/code */ |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 54 | |
| 55 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 56 | /* machine variants which require cc -Dmachine: pdp11, z8000, DOS */ |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 57 | #define FAST |
| 58 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 59 | #define HBITS 17 /* 50% occupancy */ |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 60 | #define HSIZE (1<<HBITS) |
| 61 | #define HMASK (HSIZE-1) |
| 62 | #define HPRIME 9941 |
| 63 | #define BITS 16 |
| 64 | #undef MAXSEG_64K |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 65 | #define MAXCODE(n) (1L << (n)) |
| 66 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 67 | /* Block compress mode -C compatible with 2.0 */ |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 68 | static int block_mode = BLOCK_MODE; |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 69 | |
| 70 | /* user settable max # bits/code */ |
Eric Andersen | 14f5c8d | 2005-04-16 19:39:00 +0000 | [diff] [blame] | 71 | static int maxbits = BITS; |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 72 | |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 73 | #define htabof(i) htab[i] |
| 74 | #define codetabof(i) codetab[i] |
| 75 | #define tab_prefixof(i) codetabof(i) |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 76 | #define tab_suffixof(i) ((unsigned char *)(htab))[i] |
| 77 | #define de_stack ((unsigned char *)&(htab[HSIZE-1])) |
Bernhard Reutner-Fischer | 5d72546 | 2006-09-06 15:28:32 +0000 | [diff] [blame] | 78 | #define clear_htab() memset(htab, -1, HSIZE) |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 79 | #define clear_tab_prefixof() memset(codetab, 0, 256); |
| 80 | |
| 81 | |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 82 | /* |
| 83 | * Decompress stdin to stdout. This routine adapts to the codes in the |
| 84 | * file building the "string" table on-the-fly; requiring no table to |
| 85 | * be stored in the compressed file. The tables used herein are shared |
| 86 | * with those of the compress() routine. See the definitions above. |
| 87 | */ |
| 88 | |
Denis Vlasenko | 97a8dd3 | 2006-10-01 15:55:11 +0000 | [diff] [blame] | 89 | USE_DESKTOP(long long) int |
| 90 | uncompress(int fd_in, int fd_out) |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 91 | { |
Denis Vlasenko | 97a8dd3 | 2006-10-01 15:55:11 +0000 | [diff] [blame] | 92 | USE_DESKTOP(long long total_written = 0;) |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 93 | unsigned char *stackp; |
| 94 | long int code; |
| 95 | int finchar; |
| 96 | long int oldcode; |
| 97 | long int incode; |
| 98 | int inbits; |
| 99 | int posbits; |
| 100 | int outpos; |
| 101 | int insize; |
| 102 | int bitmask; |
| 103 | long int free_ent; |
| 104 | long int maxcode; |
| 105 | long int maxmaxcode; |
| 106 | int n_bits; |
| 107 | int rsize = 0; |
Bernhard Reutner-Fischer | 5d72546 | 2006-09-06 15:28:32 +0000 | [diff] [blame] | 108 | RESERVE_CONFIG_UBUFFER(inbuf, IBUFSIZ + 64); |
| 109 | RESERVE_CONFIG_UBUFFER(outbuf, OBUFSIZ + 2048); |
| 110 | unsigned char htab[HSIZE]; |
| 111 | unsigned short codetab[HSIZE]; |
| 112 | memset(inbuf, 0, IBUFSIZ + 64); |
| 113 | memset(outbuf, 0, OBUFSIZ + 2048); |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 114 | |
| 115 | insize = 0; |
| 116 | |
Rob Landley | 5343747 | 2006-07-16 08:14:35 +0000 | [diff] [blame] | 117 | inbuf[0] = xread_char(fd_in); |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 118 | |
| 119 | maxbits = inbuf[0] & BIT_MASK; |
| 120 | block_mode = inbuf[0] & BLOCK_MODE; |
| 121 | maxmaxcode = MAXCODE(maxbits); |
| 122 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 123 | if (maxbits > BITS) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 124 | bb_error_msg("compressed with %d bits, can only handle %d bits", maxbits, |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 125 | BITS); |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 126 | return -1; |
| 127 | } |
| 128 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 129 | maxcode = MAXCODE(n_bits = INIT_BITS) - 1; |
| 130 | bitmask = (1 << n_bits) - 1; |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 131 | oldcode = -1; |
| 132 | finchar = 0; |
| 133 | outpos = 0; |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 134 | posbits = 0 << 3; |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 135 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 136 | free_ent = ((block_mode) ? FIRST : 256); |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 137 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 138 | /* As above, initialize the first 256 entries in the table. */ |
| 139 | clear_tab_prefixof(); |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 140 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 141 | for (code = 255; code >= 0; --code) { |
| 142 | tab_suffixof(code) = (unsigned char) code; |
| 143 | } |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 144 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 145 | do { |
| 146 | resetbuf:; |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 147 | { |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 148 | int i; |
| 149 | int e; |
| 150 | int o; |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 151 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 152 | e = insize - (o = (posbits >> 3)); |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 153 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 154 | for (i = 0; i < e; ++i) |
| 155 | inbuf[i] = inbuf[i + o]; |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 156 | |
| 157 | insize = e; |
| 158 | posbits = 0; |
| 159 | } |
| 160 | |
Bernhard Reutner-Fischer | 5d72546 | 2006-09-06 15:28:32 +0000 | [diff] [blame] | 161 | if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) { |
Glenn L McGrath | 1a2d75f | 2003-11-21 22:17:28 +0000 | [diff] [blame] | 162 | rsize = safe_read(fd_in, inbuf + insize, IBUFSIZ); |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 163 | insize += rsize; |
| 164 | } |
| 165 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 166 | inbits = ((rsize > 0) ? (insize - insize % n_bits) << 3 : |
| 167 | (insize << 3) - (n_bits - 1)); |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 168 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 169 | while (inbits > posbits) { |
| 170 | if (free_ent > maxcode) { |
| 171 | posbits = |
| 172 | ((posbits - 1) + |
| 173 | ((n_bits << 3) - |
| 174 | (posbits - 1 + (n_bits << 3)) % (n_bits << 3))); |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 175 | ++n_bits; |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 176 | if (n_bits == maxbits) { |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 177 | maxcode = maxmaxcode; |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 178 | } else { |
| 179 | maxcode = MAXCODE(n_bits) - 1; |
| 180 | } |
| 181 | bitmask = (1 << n_bits) - 1; |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 182 | goto resetbuf; |
| 183 | } |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 184 | { |
| 185 | unsigned char *p = &inbuf[posbits >> 3]; |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 186 | |
Denis Vlasenko | 97a8dd3 | 2006-10-01 15:55:11 +0000 | [diff] [blame] | 187 | code = ((((long) (p[0])) | ((long) (p[1]) << 8) | |
| 188 | ((long) (p[2]) << 16)) >> (posbits & 0x7)) & bitmask; |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 189 | } |
| 190 | posbits += n_bits; |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 191 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 192 | |
| 193 | if (oldcode == -1) { |
Denis Vlasenko | 97a8dd3 | 2006-10-01 15:55:11 +0000 | [diff] [blame] | 194 | oldcode = code; |
| 195 | finchar = (int) oldcode; |
| 196 | outbuf[outpos++] = (unsigned char) finchar; |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 197 | continue; |
| 198 | } |
| 199 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 200 | if (code == CLEAR && block_mode) { |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 201 | clear_tab_prefixof(); |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 202 | free_ent = FIRST - 1; |
| 203 | posbits = |
| 204 | ((posbits - 1) + |
| 205 | ((n_bits << 3) - |
| 206 | (posbits - 1 + (n_bits << 3)) % (n_bits << 3))); |
| 207 | maxcode = MAXCODE(n_bits = INIT_BITS) - 1; |
| 208 | bitmask = (1 << n_bits) - 1; |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 209 | goto resetbuf; |
| 210 | } |
| 211 | |
| 212 | incode = code; |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 213 | stackp = de_stack; |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 214 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 215 | /* Special case for KwKwK string. */ |
| 216 | if (code >= free_ent) { |
| 217 | if (code > free_ent) { |
| 218 | unsigned char *p; |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 219 | |
| 220 | posbits -= n_bits; |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 221 | p = &inbuf[posbits >> 3]; |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 222 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 223 | bb_error_msg |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 224 | ("insize:%d posbits:%d inbuf:%02X %02X %02X %02X %02X (%d)", |
| 225 | insize, posbits, p[-1], p[0], p[1], p[2], p[3], |
| 226 | (posbits & 07)); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 227 | bb_error_msg("uncompress: corrupt input"); |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 228 | return -1; |
| 229 | } |
| 230 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 231 | *--stackp = (unsigned char) finchar; |
| 232 | code = oldcode; |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 235 | /* Generate output characters in reverse order */ |
| 236 | while ((long int) code >= (long int) 256) { |
| 237 | *--stackp = tab_suffixof(code); |
| 238 | code = tab_prefixof(code); |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 239 | } |
| 240 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 241 | *--stackp = (unsigned char) (finchar = tab_suffixof(code)); |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 242 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 243 | /* And put them out in forward order */ |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 244 | { |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 245 | int i; |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 246 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 247 | if (outpos + (i = (de_stack - stackp)) >= OBUFSIZ) { |
| 248 | do { |
| 249 | if (i > OBUFSIZ - outpos) { |
| 250 | i = OBUFSIZ - outpos; |
| 251 | } |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 252 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 253 | if (i > 0) { |
| 254 | memcpy(outbuf + outpos, stackp, i); |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 255 | outpos += i; |
| 256 | } |
| 257 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 258 | if (outpos >= OBUFSIZ) { |
Glenn L McGrath | 2e41d0c | 2002-09-27 06:46:02 +0000 | [diff] [blame] | 259 | write(fd_out, outbuf, outpos); |
Denis Vlasenko | 97a8dd3 | 2006-10-01 15:55:11 +0000 | [diff] [blame] | 260 | USE_DESKTOP(total_written += outpos;) |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 261 | outpos = 0; |
| 262 | } |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 263 | stackp += i; |
| 264 | } while ((i = (de_stack - stackp)) > 0); |
| 265 | } else { |
| 266 | memcpy(outbuf + outpos, stackp, i); |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 267 | outpos += i; |
| 268 | } |
| 269 | } |
| 270 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 271 | /* Generate the new entry. */ |
| 272 | if ((code = free_ent) < maxmaxcode) { |
| 273 | tab_prefixof(code) = (unsigned short) oldcode; |
| 274 | tab_suffixof(code) = (unsigned char) finchar; |
| 275 | free_ent = code + 1; |
| 276 | } |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 277 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 278 | /* Remember previous code. */ |
| 279 | oldcode = incode; |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Glenn L McGrath | fedbfe4 | 2002-11-28 09:09:47 +0000 | [diff] [blame] | 282 | } while (rsize > 0); |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 283 | |
Glenn L McGrath | 2e41d0c | 2002-09-27 06:46:02 +0000 | [diff] [blame] | 284 | if (outpos > 0) { |
| 285 | write(fd_out, outbuf, outpos); |
Denis Vlasenko | 97a8dd3 | 2006-10-01 15:55:11 +0000 | [diff] [blame] | 286 | USE_DESKTOP(total_written += outpos;) |
Glenn L McGrath | 2e41d0c | 2002-09-27 06:46:02 +0000 | [diff] [blame] | 287 | } |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 288 | |
Bernhard Reutner-Fischer | 5d72546 | 2006-09-06 15:28:32 +0000 | [diff] [blame] | 289 | RELEASE_CONFIG_BUFFER(inbuf); |
| 290 | RELEASE_CONFIG_BUFFER(outbuf); |
Denis Vlasenko | 97a8dd3 | 2006-10-01 15:55:11 +0000 | [diff] [blame] | 291 | return USE_DESKTOP(total_written) + 0; |
Robert Griebl | 94a6a95 | 2002-05-19 19:00:14 +0000 | [diff] [blame] | 292 | } |