diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-26 15:59:37 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-06-26 15:59:37 +0000 |
commit | e8240f19bd99802e0ccb1738b2d2e630b6eb9087 (patch) | |
tree | d9b7c5da8a146e809140d0c8c9e270df765159f9 | |
parent | 1fc6238ffab2cbd09b9ce573b99d82f3eaeb5b77 (diff) | |
download | busybox-w32-e8240f19bd99802e0ccb1738b2d2e630b6eb9087.tar.gz busybox-w32-e8240f19bd99802e0ccb1738b2d2e630b6eb9087.tar.bz2 busybox-w32-e8240f19bd99802e0ccb1738b2d2e630b6eb9087.zip |
uuencode: shrink
function old new delta
uuencode_main 427 337 -90
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-90) Total: -90 bytes
text data bss dec hex filename
734981 3028 14400 752409 b7b19 busybox_old
734889 3028 14400 752317 b7abd busybox_unstripped
-rw-r--r-- | coreutils/uuencode.c | 62 | ||||
-rw-r--r-- | include/libbb.h | 2 | ||||
-rw-r--r-- | libbb/uuencode.c | 5 | ||||
-rw-r--r-- | networking/wget.c | 4 |
4 files changed, 31 insertions, 42 deletions
diff --git a/coreutils/uuencode.c b/coreutils/uuencode.c index b54e317a2..c1458f7fb 100644 --- a/coreutils/uuencode.c +++ b/coreutils/uuencode.c | |||
@@ -10,64 +10,52 @@ | |||
10 | 10 | ||
11 | #include "libbb.h" | 11 | #include "libbb.h" |
12 | 12 | ||
13 | enum { | ||
14 | SRC_BUF_SIZE = 45, /* This *MUST* be a multiple of 3 */ | ||
15 | DST_BUF_SIZE = 4 * ((SRC_BUF_SIZE + 2) / 3), | ||
16 | }; | ||
13 | 17 | ||
14 | #define SRC_BUF_SIZE 45 // This *MUST* be a multiple of 3 | ||
15 | #define DST_BUF_SIZE 4 * ((SRC_BUF_SIZE + 2) / 3) | ||
16 | int uuencode_main(int argc, char **argv); | 18 | int uuencode_main(int argc, char **argv); |
17 | int uuencode_main(int argc, char **argv) | 19 | int uuencode_main(int argc, char **argv) |
18 | { | 20 | { |
19 | const size_t src_buf_size = SRC_BUF_SIZE; | ||
20 | const size_t dst_buf_size = DST_BUF_SIZE; | ||
21 | size_t write_size = dst_buf_size; | ||
22 | struct stat stat_buf; | 21 | struct stat stat_buf; |
23 | FILE *src_stream = stdin; | 22 | int src_fd = STDIN_FILENO; |
24 | const char *tbl; | 23 | const char *tbl; |
25 | size_t size; | ||
26 | mode_t mode; | 24 | mode_t mode; |
27 | RESERVE_CONFIG_BUFFER(src_buf, SRC_BUF_SIZE + 1); | 25 | char src_buf[SRC_BUF_SIZE]; |
28 | RESERVE_CONFIG_BUFFER(dst_buf, DST_BUF_SIZE + 1); | 26 | char dst_buf[DST_BUF_SIZE + 1]; |
29 | 27 | ||
30 | tbl = bb_uuenc_tbl_std; | 28 | tbl = bb_uuenc_tbl_std; |
29 | mode = 0666 & ~umask(0666); | ||
30 | opt_complementary = "-1:?2"; /* must have 1 or 2 args */ | ||
31 | if (getopt32(argc, argv, "m")) { | 31 | if (getopt32(argc, argv, "m")) { |
32 | tbl = bb_uuenc_tbl_base64; | 32 | tbl = bb_uuenc_tbl_base64; |
33 | } | 33 | } |
34 | 34 | argv += optind; | |
35 | switch (argc - optind) { | 35 | if (argc == optind + 2) { |
36 | case 2: | 36 | src_fd = xopen(*argv, O_RDONLY); |
37 | src_stream = xfopen(argv[optind], "r"); | 37 | fstat(src_fd, &stat_buf); |
38 | xstat(argv[optind], &stat_buf); | 38 | mode = stat_buf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO); |
39 | mode = stat_buf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO); | 39 | argv++; |
40 | break; | ||
41 | case 1: | ||
42 | mode = 0666 & ~umask(0666); | ||
43 | break; | ||
44 | default: | ||
45 | bb_show_usage(); | ||
46 | } | 40 | } |
47 | 41 | ||
48 | printf("begin%s %o %s", tbl == bb_uuenc_tbl_std ? "" : "-base64", mode, argv[argc - 1]); | 42 | printf("begin%s %o %s", tbl == bb_uuenc_tbl_std ? "" : "-base64", mode, *argv); |
49 | 43 | while (1) { | |
50 | while ((size = fread(src_buf, 1, src_buf_size, src_stream)) > 0) { | 44 | size_t size = full_read(src_fd, src_buf, SRC_BUF_SIZE); |
51 | if (size != src_buf_size) { | 45 | if (!size) |
52 | /* write_size is always 60 until the last line */ | 46 | break; |
53 | write_size = (4 * ((size + 2) / 3)); | 47 | if ((ssize_t)size < 0) |
54 | /* pad with 0s so we can just encode extra bits */ | 48 | bb_perror_msg_and_die(bb_msg_read_error); |
55 | memset(&src_buf[size], 0, src_buf_size - size); | ||
56 | } | ||
57 | /* Encode the buffer we just read in */ | 49 | /* Encode the buffer we just read in */ |
58 | bb_uuencode((unsigned char*)src_buf, dst_buf, size, tbl); | 50 | bb_uuencode(dst_buf, src_buf, size, tbl); |
59 | |||
60 | putchar('\n'); | 51 | putchar('\n'); |
61 | if (tbl == bb_uuenc_tbl_std) { | 52 | if (tbl == bb_uuenc_tbl_std) { |
62 | putchar(tbl[size]); | 53 | putchar(tbl[size]); |
63 | } | 54 | } |
64 | if (fwrite(dst_buf, 1, write_size, stdout) != write_size) { | 55 | fflush(stdout); |
65 | bb_perror_msg_and_die(bb_msg_write_error); | 56 | xwrite(STDOUT_FILENO, dst_buf, 4 * ((size + 2) / 3)); |
66 | } | ||
67 | } | 57 | } |
68 | printf(tbl == bb_uuenc_tbl_std ? "\n`\nend\n" : "\n====\n"); | 58 | printf(tbl == bb_uuenc_tbl_std ? "\n`\nend\n" : "\n====\n"); |
69 | 59 | ||
70 | die_if_ferror(src_stream, "source"); /* TODO - Fix this! */ | ||
71 | |||
72 | fflush_stdout_and_exit(EXIT_SUCCESS); | 60 | fflush_stdout_and_exit(EXIT_SUCCESS); |
73 | } | 61 | } |
diff --git a/include/libbb.h b/include/libbb.h index 3cdf28fab..124b11fa8 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -884,7 +884,7 @@ pid_t *pidlist_reverse(pid_t *pidList); | |||
884 | 884 | ||
885 | extern const char bb_uuenc_tbl_base64[]; | 885 | extern const char bb_uuenc_tbl_base64[]; |
886 | extern const char bb_uuenc_tbl_std[]; | 886 | extern const char bb_uuenc_tbl_std[]; |
887 | void bb_uuencode(const unsigned char *s, char *store, const int length, const char *tbl); | 887 | void bb_uuencode(char *store, const void *s, int length, const char *tbl); |
888 | 888 | ||
889 | typedef struct sha1_ctx_t { | 889 | typedef struct sha1_ctx_t { |
890 | uint32_t count[2]; | 890 | uint32_t count[2]; |
diff --git a/libbb/uuencode.c b/libbb/uuencode.c index bbb92d600..08fe3f366 100644 --- a/libbb/uuencode.c +++ b/libbb/uuencode.c | |||
@@ -34,14 +34,15 @@ const char bb_uuenc_tbl_std[65] = { | |||
34 | }; | 34 | }; |
35 | 35 | ||
36 | /* | 36 | /* |
37 | * Encode the string S of length LENGTH to base64 format and place it | 37 | * Encode bytes at S of length LENGTH to uuencode or base64 format and place it |
38 | * to STORE. STORE will be 0-terminated, and must point to a writable | 38 | * to STORE. STORE will be 0-terminated, and must point to a writable |
39 | * buffer of at least 1+BASE64_LENGTH(length) bytes. | 39 | * buffer of at least 1+BASE64_LENGTH(length) bytes. |
40 | * where BASE64_LENGTH(len) = (4 * ((LENGTH + 2) / 3)) | 40 | * where BASE64_LENGTH(len) = (4 * ((LENGTH + 2) / 3)) |
41 | */ | 41 | */ |
42 | void bb_uuencode(const unsigned char *s, char *store, const int length, const char *tbl) | 42 | void bb_uuencode(char *store, const void *src, int length, const char *tbl) |
43 | { | 43 | { |
44 | int i; | 44 | int i; |
45 | const unsigned char *s = src; | ||
45 | char *p = store; | 46 | char *p = store; |
46 | 47 | ||
47 | /* Transform the 3x8 bits to 4x6 bits, as required by base64. */ | 48 | /* Transform the 3x8 bits to 4x6 bits, as required by base64. */ |
diff --git a/networking/wget.c b/networking/wget.c index ef27ab058..bd9480ce5 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -76,9 +76,9 @@ static char *safe_fgets(char *s, int size, FILE *stream) | |||
76 | 76 | ||
77 | #if ENABLE_FEATURE_WGET_AUTHENTICATION | 77 | #if ENABLE_FEATURE_WGET_AUTHENTICATION |
78 | /* Base64-encode character string and return the string. */ | 78 | /* Base64-encode character string and return the string. */ |
79 | static char *base64enc(unsigned char *p, char *buf, int len) | 79 | static char *base64enc(const unsigned char *p, char *buf, int len) |
80 | { | 80 | { |
81 | bb_uuencode(p, buf, len, bb_uuenc_tbl_base64); | 81 | bb_uuencode(buf, p, len, bb_uuenc_tbl_base64); |
82 | return buf; | 82 | return buf; |
83 | } | 83 | } |
84 | #endif | 84 | #endif |