diff options
author | Denys Vlasenko <dvlasenk@redhat.com> | 2010-08-31 14:09:22 +0200 |
---|---|---|
committer | Denys Vlasenko <dvlasenk@redhat.com> | 2010-08-31 14:09:22 +0200 |
commit | ee06264a29c81a2d309c9919222d61ff92aa7b7c (patch) | |
tree | e758f420e9547748aca986356ec0c6d6d7f889d9 /coreutils/uudecode.c | |
parent | 8d3e225a2d1d980bcedb825f294b6a8041fe3f1b (diff) | |
download | busybox-w32-ee06264a29c81a2d309c9919222d61ff92aa7b7c.tar.gz busybox-w32-ee06264a29c81a2d309c9919222d61ff92aa7b7c.tar.bz2 busybox-w32-ee06264a29c81a2d309c9919222d61ff92aa7b7c.zip |
base64: new applet
function old new delta
base64_main - 217 +217
packed_usage 27181 27229 +48
read_base64 348 373 +25
applet_names 2299 2306 +7
bbconfig_config_bz2 4942 4948 +6
applet_main 1352 1356 +4
applet_nameofs 676 678 +2
applet_install_loc 169 170 +1
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 7/0 up/down: 310/0) Total: 310 bytes
Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
Diffstat (limited to 'coreutils/uudecode.c')
-rw-r--r-- | coreutils/uudecode.c | 78 |
1 files changed, 74 insertions, 4 deletions
diff --git a/coreutils/uudecode.c b/coreutils/uudecode.c index 06211b8ef..207fb0b8d 100644 --- a/coreutils/uudecode.c +++ b/coreutils/uudecode.c | |||
@@ -10,9 +10,9 @@ | |||
10 | * Bugs: the spec doesn't mention anything about "`\n`\n" prior to the | 10 | * Bugs: the spec doesn't mention anything about "`\n`\n" prior to the |
11 | * "end" line | 11 | * "end" line |
12 | */ | 12 | */ |
13 | |||
14 | #include "libbb.h" | 13 | #include "libbb.h" |
15 | 14 | ||
15 | #if ENABLE_UUDECODE | ||
16 | static void read_stduu(FILE *src_stream, FILE *dst_stream) | 16 | static void read_stduu(FILE *src_stream, FILE *dst_stream) |
17 | { | 17 | { |
18 | char *line; | 18 | char *line; |
@@ -73,13 +73,14 @@ static void read_stduu(FILE *src_stream, FILE *dst_stream) | |||
73 | } | 73 | } |
74 | bb_error_msg_and_die("short file"); | 74 | bb_error_msg_and_die("short file"); |
75 | } | 75 | } |
76 | #endif | ||
76 | 77 | ||
77 | static void read_base64(FILE *src_stream, FILE *dst_stream) | 78 | static void read_base64(FILE *src_stream, FILE *dst_stream) |
78 | { | 79 | { |
79 | int term_count = 1; | 80 | int term_count = 1; |
80 | 81 | ||
81 | while (1) { | 82 | while (1) { |
82 | char translated[4]; | 83 | unsigned char translated[4]; |
83 | int count = 0; | 84 | int count = 0; |
84 | 85 | ||
85 | while (count < 4) { | 86 | while (count < 4) { |
@@ -93,6 +94,12 @@ static void read_base64(FILE *src_stream, FILE *dst_stream) | |||
93 | do { | 94 | do { |
94 | ch = fgetc(src_stream); | 95 | ch = fgetc(src_stream); |
95 | if (ch == EOF) { | 96 | if (ch == EOF) { |
97 | if (ENABLE_BASE64 | ||
98 | && (!ENABLE_UUDECODE || applet_name[0] == 'b') | ||
99 | && count == 0 | ||
100 | ) { | ||
101 | return; | ||
102 | } | ||
96 | bb_error_msg_and_die("short file"); | 103 | bb_error_msg_and_die("short file"); |
97 | } | 104 | } |
98 | table_ptr = strchr(bb_uuenc_tbl_base64, ch); | 105 | table_ptr = strchr(bb_uuenc_tbl_base64, ch); |
@@ -134,6 +141,7 @@ static void read_base64(FILE *src_stream, FILE *dst_stream) | |||
134 | } | 141 | } |
135 | } | 142 | } |
136 | 143 | ||
144 | #if ENABLE_UUDECODE | ||
137 | int uudecode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 145 | int uudecode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
138 | int uudecode_main(int argc UNUSED_PARAM, char **argv) | 146 | int uudecode_main(int argc UNUSED_PARAM, char **argv) |
139 | { | 147 | { |
@@ -145,9 +153,9 @@ int uudecode_main(int argc UNUSED_PARAM, char **argv) | |||
145 | getopt32(argv, "o:", &outname); | 153 | getopt32(argv, "o:", &outname); |
146 | argv += optind; | 154 | argv += optind; |
147 | 155 | ||
148 | if (!*argv) | 156 | if (!argv[0]) |
149 | *--argv = (char*)"-"; | 157 | *--argv = (char*)"-"; |
150 | src_stream = xfopen_stdin(*argv); | 158 | src_stream = xfopen_stdin(argv[0]); |
151 | 159 | ||
152 | /* Search for the start of the encoding */ | 160 | /* Search for the start of the encoding */ |
153 | while ((line = xmalloc_fgetline(src_stream)) != NULL) { | 161 | while ((line = xmalloc_fgetline(src_stream)) != NULL) { |
@@ -188,6 +196,68 @@ int uudecode_main(int argc UNUSED_PARAM, char **argv) | |||
188 | } | 196 | } |
189 | bb_error_msg_and_die("no 'begin' line"); | 197 | bb_error_msg_and_die("no 'begin' line"); |
190 | } | 198 | } |
199 | #endif | ||
200 | |||
201 | //applet:IF_BASE64(APPLET(base64, _BB_DIR_BIN, _BB_SUID_DROP)) | ||
202 | |||
203 | //kbuild:lib-$(CONFIG_BASE64) += uudecode.o | ||
204 | |||
205 | //config:config BASE64 | ||
206 | //config: bool "base64" | ||
207 | //config: default y | ||
208 | //config: help | ||
209 | //config: Base64 encode and decode | ||
210 | |||
211 | //usage:#define base64_trivial_usage | ||
212 | //usage: "[-d] [FILE]" | ||
213 | //usage:#define base64_full_usage "\n\n" | ||
214 | //usage: "Base64 encode or decode FILE to standard output" | ||
215 | //usage: "\nOptions:" | ||
216 | //usage: "\n -d Decode data" | ||
217 | ////usage: "\n -w COL Wrap lines at COL (default 76, 0 disables)" | ||
218 | ////usage: "\n -i When decoding, ignore non-alphabet characters" | ||
219 | |||
220 | #if ENABLE_BASE64 | ||
221 | int base64_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
222 | int base64_main(int argc UNUSED_PARAM, char **argv) | ||
223 | { | ||
224 | FILE *src_stream; | ||
225 | unsigned opts; | ||
226 | |||
227 | opt_complementary = "?1"; /* 1 argument max */ | ||
228 | opts = getopt32(argv, "d"); | ||
229 | argv += optind; | ||
230 | |||
231 | if (!argv[0]) | ||
232 | *--argv = (char*)"-"; | ||
233 | src_stream = xfopen_stdin(argv[0]); | ||
234 | if (opts) { | ||
235 | read_base64(src_stream, stdout); | ||
236 | } else { | ||
237 | enum { | ||
238 | SRC_BUF_SIZE = 76/4*3, /* This *MUST* be a multiple of 3 */ | ||
239 | DST_BUF_SIZE = 4 * ((SRC_BUF_SIZE + 2) / 3), | ||
240 | }; | ||
241 | char src_buf[SRC_BUF_SIZE]; | ||
242 | char dst_buf[DST_BUF_SIZE + 1]; | ||
243 | int src_fd = fileno(src_stream); | ||
244 | while (1) { | ||
245 | size_t size = full_read(src_fd, src_buf, SRC_BUF_SIZE); | ||
246 | if (!size) | ||
247 | break; | ||
248 | if ((ssize_t)size < 0) | ||
249 | bb_perror_msg_and_die(bb_msg_read_error); | ||
250 | /* Encode the buffer we just read in */ | ||
251 | bb_uuencode(dst_buf, src_buf, size, bb_uuenc_tbl_base64); | ||
252 | xwrite(STDOUT_FILENO, dst_buf, 4 * ((size + 2) / 3)); | ||
253 | bb_putchar('\n'); | ||
254 | fflush(stdout); | ||
255 | } | ||
256 | } | ||
257 | |||
258 | fflush_stdout_and_exit(EXIT_SUCCESS); | ||
259 | } | ||
260 | #endif | ||
191 | 261 | ||
192 | /* Test script. | 262 | /* Test script. |
193 | Put this into an empty dir with busybox binary, an run. | 263 | Put this into an empty dir with busybox binary, an run. |