blob: 63a8d4d4871694dd2ab18481288b2fd1defe5258 [file] [log] [blame]
"Robert P. J. Day"63fc1a92006-07-02 19:47:05 +00001/* vi: set sw=4 ts=4: */
Glenn L McGrath7f9de022003-11-06 03:17:23 +00002/*
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02003 * Copyright 2003, Glenn McGrath
Eric Andersen2b6ab3c2000-06-13 06:54:53 +00004 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02005 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Eric Andersen4e573f42000-11-14 23:29:24 +00006 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Based on specification from
8 * http://www.opengroup.org/onlinepubs/007904975/utilities/uuencode.html
Eric Andersen4e573f42000-11-14 23:29:24 +00009 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +020010 * Bugs: the spec doesn't mention anything about "`\n`\n" prior to the
11 * "end" line
Eric Andersen2b6ab3c2000-06-13 06:54:53 +000012 */
Denys Vlasenkoaf3f4202016-11-23 14:46:56 +010013//config:config UUDECODE
Denys Vlasenkob097a842018-12-28 03:20:17 +010014//config: bool "uudecode (5.8 kb)"
Denys Vlasenkoaf3f4202016-11-23 14:46:56 +010015//config: default y
16//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020017//config: uudecode is used to decode a uuencoded file.
Denys Vlasenkoaf3f4202016-11-23 14:46:56 +010018
19//applet:IF_UUDECODE(APPLET(uudecode, BB_DIR_USR_BIN, BB_SUID_DROP))
20
21//kbuild:lib-$(CONFIG_UUDECODE) += uudecode.o
Pere Orga34425382011-03-31 14:43:25 +020022
23//usage:#define uudecode_trivial_usage
24//usage: "[-o OUTFILE] [INFILE]"
25//usage:#define uudecode_full_usage "\n\n"
26//usage: "Uudecode a file\n"
Denys Vlasenko11e61d52012-03-05 14:23:26 +010027//usage: "Finds OUTFILE in uuencoded source unless -o is given"
Pere Orga34425382011-03-31 14:43:25 +020028//usage:
29//usage:#define uudecode_example_usage
30//usage: "$ uudecode -o busybox busybox.uu\n"
31//usage: "$ ls -l busybox\n"
32//usage: "-rwxr-xr-x 1 ams ams 245264 Jun 7 21:35 busybox\n"
33
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000034#include "libbb.h"
Eric Andersen2b6ab3c2000-06-13 06:54:53 +000035
Denys Vlasenkoee062642010-08-31 14:09:22 +020036#if ENABLE_UUDECODE
Denys Vlasenko9fe98f72010-09-16 17:51:13 +020037static void FAST_FUNC read_stduu(FILE *src_stream, FILE *dst_stream, int flags UNUSED_PARAM)
Eric Andersen2b6ab3c2000-06-13 06:54:53 +000038{
Glenn L McGrath7f9de022003-11-06 03:17:23 +000039 char *line;
Eric Andersen2b6ab3c2000-06-13 06:54:53 +000040
Denys Vlasenko2b48c382015-10-05 15:10:44 +020041 for (;;) {
Denis Vlasenko62a90cd2008-03-17 09:07:36 +000042 int encoded_len, str_len;
43 char *line_ptr, *dst;
Denys Vlasenko2b48c382015-10-05 15:10:44 +020044 size_t line_len;
45
46 line_len = 64 * 1024;
47 line = xmalloc_fgets_str_len(src_stream, "\n", &line_len);
48 if (!line)
49 break;
Denys Vlasenko7b6e8f32017-07-14 17:24:59 +020050 /* Handle both Unix and MSDOS text.
51 * Note: space should not be trimmed, some encoders use it instead of "`"
52 * for padding of last incomplete 4-char block.
53 */
Denys Vlasenko2b48c382015-10-05 15:10:44 +020054 str_len = line_len;
Denys Vlasenko7b6e8f32017-07-14 17:24:59 +020055 while (--str_len >= 0
56 && (line[str_len] == '\n' || line[str_len] == '\r')
57 ) {
Denys Vlasenko2b48c382015-10-05 15:10:44 +020058 line[str_len] = '\0';
Denys Vlasenko7b6e8f32017-07-14 17:24:59 +020059 }
Eric Andersen2b6ab3c2000-06-13 06:54:53 +000060
Glenn L McGrath7f9de022003-11-06 03:17:23 +000061 if (strcmp(line, "end") == 0) {
Denis Vlasenko62a90cd2008-03-17 09:07:36 +000062 return; /* the only non-error exit */
Glenn L McGrath7f9de022003-11-06 03:17:23 +000063 }
Eric Andersen2b6ab3c2000-06-13 06:54:53 +000064
Denis Vlasenko62a90cd2008-03-17 09:07:36 +000065 line_ptr = line;
66 while (*line_ptr) {
67 *line_ptr = (*line_ptr - 0x20) & 0x3f;
68 line_ptr++;
69 }
70 str_len = line_ptr - line;
71
72 encoded_len = line[0] * 4 / 3;
73 /* Check that line is not too short. (we tolerate
Denys Vlasenko7b6e8f32017-07-14 17:24:59 +020074 * overly _long_ line to accommodate possible extra "`").
Denis Vlasenko62a90cd2008-03-17 09:07:36 +000075 * Empty line case is also caught here. */
76 if (str_len <= encoded_len) {
77 break; /* go to bb_error_msg_and_die("short file"); */
78 }
79 if (encoded_len <= 0) {
Glenn L McGrath7f9de022003-11-06 03:17:23 +000080 /* Ignore the "`\n" line, why is it even in the encode file ? */
Denis Vlasenko62a90cd2008-03-17 09:07:36 +000081 free(line);
Glenn L McGrath7f9de022003-11-06 03:17:23 +000082 continue;
83 }
Denis Vlasenko62a90cd2008-03-17 09:07:36 +000084 if (encoded_len > 60) {
James Byrne69374872019-07-02 11:35:03 +020085 bb_simple_error_msg_and_die("line too long");
Glenn L McGrath7f9de022003-11-06 03:17:23 +000086 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +000087
Denis Vlasenko62a90cd2008-03-17 09:07:36 +000088 dst = line;
89 line_ptr = line + 1;
90 do {
Glenn L McGrath7f9de022003-11-06 03:17:23 +000091 /* Merge four 6 bit chars to three 8 bit chars */
Denis Vlasenko62a90cd2008-03-17 09:07:36 +000092 *dst++ = line_ptr[0] << 2 | line_ptr[1] >> 4;
93 encoded_len--;
94 if (encoded_len == 0) {
Glenn L McGrath7f9de022003-11-06 03:17:23 +000095 break;
96 }
Eric Andersen2b6ab3c2000-06-13 06:54:53 +000097
Denis Vlasenko62a90cd2008-03-17 09:07:36 +000098 *dst++ = line_ptr[1] << 4 | line_ptr[2] >> 2;
99 encoded_len--;
100 if (encoded_len == 0) {
Glenn L McGrath7f9de022003-11-06 03:17:23 +0000101 break;
102 }
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000103
Denis Vlasenko62a90cd2008-03-17 09:07:36 +0000104 *dst++ = line_ptr[2] << 6 | line_ptr[3];
105 line_ptr += 4;
106 encoded_len -= 2;
107 } while (encoded_len > 0);
108 fwrite(line, 1, dst - line, dst_stream);
Glenn L McGrath7f9de022003-11-06 03:17:23 +0000109 free(line);
110 }
James Byrne69374872019-07-02 11:35:03 +0200111 bb_simple_error_msg_and_die("short file");
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000112}
113
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000114int uudecode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000115int uudecode_main(int argc UNUSED_PARAM, char **argv)
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000116{
Denis Vlasenko62a90cd2008-03-17 09:07:36 +0000117 FILE *src_stream;
Glenn L McGrath7f9de022003-11-06 03:17:23 +0000118 char *outname = NULL;
119 char *line;
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000120
Denys Vlasenko22542ec2017-08-08 21:55:02 +0200121 getopt32(argv, "^" "o:" "\0" "?1"/* 1 arg max*/, &outname);
Denis Vlasenko746204b2007-06-04 23:32:35 +0000122 argv += optind;
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000123
Denys Vlasenkoee062642010-08-31 14:09:22 +0200124 if (!argv[0])
Denis Vlasenko62a90cd2008-03-17 09:07:36 +0000125 *--argv = (char*)"-";
Denys Vlasenkoee062642010-08-31 14:09:22 +0200126 src_stream = xfopen_stdin(argv[0]);
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000127
Glenn L McGrath7f9de022003-11-06 03:17:23 +0000128 /* Search for the start of the encoding */
Denis Vlasenko8ee649a2008-03-26 20:04:27 +0000129 while ((line = xmalloc_fgetline(src_stream)) != NULL) {
Denys Vlasenko9fe98f72010-09-16 17:51:13 +0200130 void FAST_FUNC (*decode_fn_ptr)(FILE *src, FILE *dst, int flags);
Rob Landley29d94b92006-09-23 19:56:21 +0000131 char *line_ptr;
132 FILE *dst_stream;
133 int mode;
Denis Vlasenkof7996f32007-01-11 17:20:00 +0000134
Denys Vlasenko8dff01d2015-03-12 17:48:34 +0100135 if (is_prefixed_with(line, "begin-base64 ")) {
Glenn L McGrath7f9de022003-11-06 03:17:23 +0000136 line_ptr = line + 13;
137 decode_fn_ptr = read_base64;
Denys Vlasenko8dff01d2015-03-12 17:48:34 +0100138 } else if (is_prefixed_with(line, "begin ")) {
Glenn L McGrath7f9de022003-11-06 03:17:23 +0000139 line_ptr = line + 6;
140 decode_fn_ptr = read_stduu;
Rob Landley29d94b92006-09-23 19:56:21 +0000141 } else {
142 free(line);
143 continue;
Glenn L McGrath7f9de022003-11-06 03:17:23 +0000144 }
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000145
Denis Vlasenko746204b2007-06-04 23:32:35 +0000146 /* begin line found. decode and exit */
Denis Vlasenko62a90cd2008-03-17 09:07:36 +0000147 mode = bb_strtou(line_ptr, NULL, 8);
Rob Landley29d94b92006-09-23 19:56:21 +0000148 if (outname == NULL) {
149 outname = strchr(line_ptr, ' ');
Denys Vlasenko5f920432011-10-18 12:07:05 +0200150 if (!outname)
Rob Landley29d94b92006-09-23 19:56:21 +0000151 break;
Rob Landley29d94b92006-09-23 19:56:21 +0000152 outname++;
Denys Vlasenko2b48c382015-10-05 15:10:44 +0200153 trim(outname); /* remove trailing space (and '\r' for DOS text) */
Denys Vlasenko5f920432011-10-18 12:07:05 +0200154 if (!outname[0])
155 break;
Rob Landley29d94b92006-09-23 19:56:21 +0000156 }
Denis Vlasenko746204b2007-06-04 23:32:35 +0000157 dst_stream = stdout;
Denys Vlasenkoc7b90dc2021-12-12 00:34:15 +0100158 if (NOT_LONE_DASH(outname)
159/* https://pubs.opengroup.org/onlinepubs/9699919799/utilities/uudecode.html
160 * https://pubs.opengroup.org/onlinepubs/9699919799/utilities/uuencode.html
161 * The above says that output file name specified in input file
162 * or overridden by -o OUTFILE can be special "/dev/stdout" string.
163 * This usually works "implicitly": many systems have /dev/stdout.
164 * If ENABLE_DESKTOP, support that explicitly:
165 */
166 && (!ENABLE_DESKTOP || strcmp(outname, "/dev/stdout") != 0)
167 ) {
Denis Vlasenko5415c852008-07-21 23:05:26 +0000168 dst_stream = xfopen_for_write(outname);
Denis Vlasenko62a90cd2008-03-17 09:07:36 +0000169 fchmod(fileno(dst_stream), mode & (S_IRWXU | S_IRWXG | S_IRWXO));
Glenn L McGrath7f9de022003-11-06 03:17:23 +0000170 }
171 free(line);
Denys Vlasenko9fe98f72010-09-16 17:51:13 +0200172 decode_fn_ptr(src_stream, dst_stream, /*flags:*/ BASE64_FLAG_UU_STOP + BASE64_FLAG_NO_STOP_CHAR);
Denis Vlasenko746204b2007-06-04 23:32:35 +0000173 /* fclose_if_not_stdin(src_stream); - redundant */
Bernhard Reutner-Fischerca5b3522007-01-20 21:29:32 +0000174 return EXIT_SUCCESS;
Glenn L McGrath7f9de022003-11-06 03:17:23 +0000175 }
James Byrne69374872019-07-02 11:35:03 +0200176 bb_simple_error_msg_and_die("no 'begin' line");
Eric Andersen2b6ab3c2000-06-13 06:54:53 +0000177}
Denys Vlasenkoee062642010-08-31 14:09:22 +0200178#endif
179
Denys Vlasenko20900482020-11-25 22:47:00 +0100180//config:config BASE32
181//config: bool "base32 (4.9 kb)"
182//config: default y
183//config: help
184//config: Base32 encode and decode
Denys Vlasenkoee062642010-08-31 14:09:22 +0200185
186//config:config BASE64
Denys Vlasenkob097a842018-12-28 03:20:17 +0100187//config: bool "base64 (4.9 kb)"
Denys Vlasenkoee062642010-08-31 14:09:22 +0200188//config: default y
189//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +0200190//config: Base64 encode and decode
Denys Vlasenkoee062642010-08-31 14:09:22 +0200191
Denys Vlasenko20900482020-11-25 22:47:00 +0100192//usage:#define base32_trivial_usage
Denys Vlasenkoc8b3d9a2020-11-27 15:25:31 +0100193//usage: "[-d] [-w COL] [FILE]"
Denys Vlasenko20900482020-11-25 22:47:00 +0100194//usage:#define base32_full_usage "\n\n"
Denys Vlasenko6b6826f2021-06-13 01:08:48 +0200195//usage: "Base32 encode or decode FILE to standard output\n"
Denys Vlasenko20900482020-11-25 22:47:00 +0100196//usage: "\n -d Decode data"
Denys Vlasenkoc8b3d9a2020-11-27 15:25:31 +0100197//usage: "\n -w COL Wrap lines at COL (default 76, 0 disables)"
Denys Vlasenko20900482020-11-25 22:47:00 +0100198////usage: "\n -i When decoding, ignore non-alphabet characters"
199
Denys Vlasenkoee062642010-08-31 14:09:22 +0200200//usage:#define base64_trivial_usage
Denys Vlasenkoc8b3d9a2020-11-27 15:25:31 +0100201//usage: "[-d] [-w COL] [FILE]"
Denys Vlasenkoee062642010-08-31 14:09:22 +0200202//usage:#define base64_full_usage "\n\n"
Denys Vlasenko6b6826f2021-06-13 01:08:48 +0200203//usage: "Base64 encode or decode FILE to standard output\n"
Denys Vlasenkoee062642010-08-31 14:09:22 +0200204//usage: "\n -d Decode data"
Denys Vlasenkoc8b3d9a2020-11-27 15:25:31 +0100205//usage: "\n -w COL Wrap lines at COL (default 76, 0 disables)"
Denys Vlasenko643b3082021-06-13 23:58:17 +0200206///////: "\n -i When decoding, ignore non-alphabet characters"
207// -i is accepted but has no effect: currently, decode_base32/64() functions
208// (called via read_base64()) skip invalid chars unconditionally.
Denys Vlasenkoee062642010-08-31 14:09:22 +0200209
Denys Vlasenko20900482020-11-25 22:47:00 +0100210// APPLET_ODDNAME:name main location suid_type help
211//applet:IF_BASE32(APPLET_ODDNAME(base32, baseNUM, BB_DIR_BIN, BB_SUID_DROP, base32))
212//applet:IF_BASE64(APPLET_ODDNAME(base64, baseNUM, BB_DIR_BIN, BB_SUID_DROP, base64))
213
214//kbuild:lib-$(CONFIG_BASE64) += uudecode.o
215//kbuild:lib-$(CONFIG_BASE32) += uudecode.o
216
217#if ENABLE_BASE32 || ENABLE_BASE64
218
219# if ENABLE_BASE32
220static void bb_b32encode(char *p, const void *src, int length)
221{
222#define tbl bb_uuenc_tbl_base32
223 const unsigned char *s = src;
224
225 /* Transform 5x8 bits to 8x5 bits */
226 while (length > 0) {
227 unsigned cur, next;
228
229 length--;
230 cur = *s++;
231 *p++ = tbl[cur >> 3]; // xxxxx--- -------- -------- -------- --------
232 cur &= 7;
233
234 next = 0;
235 if (--length >= 0)
236 next = *s++;
237 *p++ = tbl[(cur << 2) + (next >> 6)]; // -----xxx xx------ -------- -------- --------
238 cur = next & 0x3f;
239
240 *p++ = tbl[cur >> 1]; // -------- --xxxxx- -------- -------- --------
241 cur &= 1;
242
243 next = 0;
244 if (--length >= 0)
245 next = *s++;
246 *p++ = tbl[(cur << 4) + (next >> 4)]; // -------- -------x xxxx---- -------- --------
247 cur = next & 0xf;
248
249 next = 0;
250 if (--length >= 0)
251 next = *s++;
252 *p++ = tbl[(cur << 1) + (next >> 7)]; // -------- -------- ----xxxx x------- --------
253 cur = next & 0x7f;
254
255 *p++ = tbl[cur >> 2]; // -------- -------- -------- -xxxxx-- --------
256 cur &= 3;
257
258 next = 0;
259 if (--length >= 0)
260 next = *s++;
261 *p++ = tbl[(cur << 3) + (next >> 5)]; // -------- -------- -------- ------xx xxx-----
262 cur = next & 0x1f;
263
264 *p++ = tbl[cur]; // -------- -------- -------- -------- ---xxxxx
265 }
266#undef tbl
267 /* Zero-terminate */
268 *p = '\0';
269 /* Pad as necessary */
270 length = ((-length) * 3) >> 1; /* -4 => 6 pad chars, -3 => 4, -2 => 3, -1 => 1 */
271 while (length--) {
272 *--p = '=';
273 }
274}
275# else
276void bb_b32encode(char *p, const void *src, int length); /* undefined */
277# endif
278
279int baseNUM_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
280int baseNUM_main(int argc UNUSED_PARAM, char **argv)
Denys Vlasenkoee062642010-08-31 14:09:22 +0200281{
282 FILE *src_stream;
283 unsigned opts;
Denys Vlasenkoc8b3d9a2020-11-27 15:25:31 +0100284 unsigned col = 76;
Denys Vlasenkoee062642010-08-31 14:09:22 +0200285
Denys Vlasenko643b3082021-06-13 23:58:17 +0200286 opts = getopt32(argv, "^" "diw:+" "\0" "?1"/* 1 arg max*/, &col);
Denys Vlasenkoee062642010-08-31 14:09:22 +0200287 argv += optind;
288
289 if (!argv[0])
290 *--argv = (char*)"-";
291 src_stream = xfopen_stdin(argv[0]);
Denys Vlasenkoc8b3d9a2020-11-27 15:25:31 +0100292 if (opts & 1) {
Denys Vlasenko818a4aa2020-11-28 14:22:52 +0100293 /* -d: decode */
Denys Vlasenko20900482020-11-25 22:47:00 +0100294 int flags = (unsigned char)EOF;
295 if (ENABLE_BASE32 && (!ENABLE_BASE64 || applet_name[4] == '3'))
296 flags = ((unsigned char)EOF) | BASE64_32;
297 read_base64(src_stream, stdout, flags);
Denys Vlasenkoee062642010-08-31 14:09:22 +0200298 } else {
299 enum {
Denys Vlasenkoc8b3d9a2020-11-27 15:25:31 +0100300 SRC_BUF_SIZE = 3 * 5 * 32, /* this *MUST* be a multiple of 3 and 5 */
Denys Vlasenko818a4aa2020-11-28 14:22:52 +0100301 DST_BUF_SIZE = 8 * ((SRC_BUF_SIZE + 4) / 5), /* max growth on encode (base32 case) */
Denys Vlasenkoee062642010-08-31 14:09:22 +0200302 };
Denys Vlasenkocdab3c42020-11-27 15:39:23 +0100303 /* Use one buffer for both input and output:
Denys Vlasenko818a4aa2020-11-28 14:22:52 +0100304 * encoding reads input "left-to-right",
Denys Vlasenkocdab3c42020-11-27 15:39:23 +0100305 * it's safe to place source at the end of the buffer and
Denys Vlasenko818a4aa2020-11-28 14:22:52 +0100306 * overwrite it while encoding, just be careful to have a gap.
Denys Vlasenkocdab3c42020-11-27 15:39:23 +0100307 */
308 char dst_buf[((DST_BUF_SIZE + /*gap:*/ 16) /*round up to 16:*/ | 0xf) + 1];
309#define src_buf (dst_buf + sizeof(dst_buf) - SRC_BUF_SIZE)
310 int src_fd, rem;
Denys Vlasenko20900482020-11-25 22:47:00 +0100311
Denys Vlasenkocdab3c42020-11-27 15:39:23 +0100312 src_fd = fileno(src_stream);
313 rem = 0;
Denys Vlasenkoc8b3d9a2020-11-27 15:25:31 +0100314 while (1) {
315 size_t size = full_read(src_fd, src_buf, SRC_BUF_SIZE);
Denys Vlasenkoee062642010-08-31 14:09:22 +0200316 if ((ssize_t)size < 0)
James Byrne69374872019-07-02 11:35:03 +0200317 bb_simple_perror_msg_and_die(bb_msg_read_error);
Denys Vlasenkoc8b3d9a2020-11-27 15:25:31 +0100318 if (size == 0) {
319 if (rem != 0) bb_putchar('\n');
320 break;
321 }
Denys Vlasenko20900482020-11-25 22:47:00 +0100322
Denys Vlasenkoee062642010-08-31 14:09:22 +0200323 /* Encode the buffer we just read in */
Denys Vlasenko20900482020-11-25 22:47:00 +0100324 if (ENABLE_BASE32 && (!ENABLE_BASE64 || applet_name[4] == '3')) {
325 bb_b32encode(dst_buf, src_buf, size);
326 size = 8 * ((size + 4) / 5);
327 } else {
328 bb_uuencode(dst_buf, src_buf, size, bb_uuenc_tbl_base64);
329 size = 4 * ((size + 2) / 3);
330 }
331
Denys Vlasenkoc8b3d9a2020-11-27 15:25:31 +0100332 if (col == 0) {
Ron Yorstoncad3fc72021-02-03 20:47:14 +0100333 fputs_stdout(dst_buf);
Denys Vlasenkoc8b3d9a2020-11-27 15:25:31 +0100334 } else {
335 char *result = dst_buf;
336 if (rem == 0)
337 rem = col;
338 while (1) {
339 int out = size < rem ? size : rem;
340 rem -= out;
341 printf(rem != 0 ? "%.*s" : "%.*s\n", out, result);
342 if (rem != 0)
343 break;
344 size -= out;
345 if (size == 0)
346 break;
347 result += out;
348 rem = col;
349 }
350 }
Denys Vlasenkoee062642010-08-31 14:09:22 +0200351 }
Denys Vlasenkocdab3c42020-11-27 15:39:23 +0100352#undef src_buf
Denys Vlasenkoee062642010-08-31 14:09:22 +0200353 }
354
Denys Vlasenko31f45c12022-01-04 23:31:58 +0100355 fflush_stdout_and_exit_SUCCESS();
Denys Vlasenkoee062642010-08-31 14:09:22 +0200356}
357#endif
Denis Vlasenko746204b2007-06-04 23:32:35 +0000358
359/* Test script.
360Put this into an empty dir with busybox binary, an run.
361
362#!/bin/sh
363test -x busybox || { echo "No ./busybox?"; exit; }
364ln -sf busybox uudecode
365ln -sf busybox uuencode
366>A_null
367echo -n A >A
368echo -n AB >AB
369echo -n ABC >ABC
370echo -n ABCD >ABCD
371echo -n ABCDE >ABCDE
372echo -n ABCDEF >ABCDEF
373cat busybox >A_bbox
374for f in A*; do
375 echo uuencode $f
376 ./uuencode $f <$f >u_$f
377 ./uuencode -m $f <$f >m_$f
378done
379mkdir unpk_u unpk_m 2>/dev/null
380for f in u_*; do
381 ./uudecode <$f -o unpk_u/${f:2}
382 diff -a ${f:2} unpk_u/${f:2} >/dev/null 2>&1
383 echo uudecode $f: $?
384done
385for f in m_*; do
386 ./uudecode <$f -o unpk_m/${f:2}
387 diff -a ${f:2} unpk_m/${f:2} >/dev/null 2>&1
388 echo uudecode $f: $?
389done
390*/