diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-07-31 17:30:08 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-07-31 17:30:08 +0200 |
commit | 8d634a08c4164da3a0d93caa9de825384e59d27d (patch) | |
tree | cfabe15456c00a6582a3b279388128faad013f6d | |
parent | f28b8857a9fa7b2b137a19ce7069077da5706d78 (diff) | |
download | busybox-w32-8d634a08c4164da3a0d93caa9de825384e59d27d.tar.gz busybox-w32-8d634a08c4164da3a0d93caa9de825384e59d27d.tar.bz2 busybox-w32-8d634a08c4164da3a0d93caa9de825384e59d27d.zip |
sendfile: code shrink
function old new delta
printstr_base64 - 22 +22
printbuf_base64 - 11 +11
printfile_base64 - 9 +9
makemime_main 305 294 -11
encode_n_base64 236 223 -13
sendmail_main 1380 1366 -14
encode_base64 36 - -36
------------------------------------------------------------------------------
(add/remove: 3/1 grow/shrink: 0/3 up/down: 42/-74) Total: -32 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | mailutils/mail.c | 35 | ||||
-rw-r--r-- | mailutils/mail.h | 5 | ||||
-rw-r--r-- | mailutils/makemime.c | 2 | ||||
-rw-r--r-- | mailutils/sendmail.c | 6 |
4 files changed, 26 insertions, 22 deletions
diff --git a/mailutils/mail.c b/mailutils/mail.c index 2ad959f7d..6726654f7 100644 --- a/mailutils/mail.c +++ b/mailutils/mail.c | |||
@@ -107,18 +107,7 @@ static char* FAST_FUNC parse_url(char *url, char **user, char **pass) | |||
107 | } | 107 | } |
108 | */ | 108 | */ |
109 | 109 | ||
110 | void FAST_FUNC encode_base64(char *fname, const char *text, const char *eol) | 110 | static void encode_n_base64(const char *fname, const char *text, size_t len) |
111 | { | ||
112 | size_t len = len; | ||
113 | if (text) { | ||
114 | // though we do not call uuencode(NULL, NULL) explicitly | ||
115 | // still we do not want to break things suddenly | ||
116 | len = strlen(text); | ||
117 | } | ||
118 | encode_n_base64(fname, text, len, eol); | ||
119 | } | ||
120 | |||
121 | void FAST_FUNC encode_n_base64(char *fname, const char *text, size_t len, const char *eol) | ||
122 | { | 111 | { |
123 | enum { | 112 | enum { |
124 | SRC_BUF_SIZE = 57, /* This *MUST* be a multiple of 3 */ | 113 | SRC_BUF_SIZE = 57, /* This *MUST* be a multiple of 3 */ |
@@ -130,10 +119,9 @@ void FAST_FUNC encode_n_base64(char *fname, const char *text, size_t len, const | |||
130 | char dst_buf[DST_BUF_SIZE + 1]; | 119 | char dst_buf[DST_BUF_SIZE + 1]; |
131 | 120 | ||
132 | if (fname) { | 121 | if (fname) { |
133 | fp = (NOT_LONE_DASH(fname)) ? xfopen_for_read(fname) : (FILE *)text; | 122 | fp = (NOT_LONE_DASH(fname)) ? xfopen_for_read(fname) : stdin; |
134 | src_buf = src; | 123 | src_buf = src; |
135 | } else if (!text) | 124 | } |
136 | return; | ||
137 | 125 | ||
138 | while (1) { | 126 | while (1) { |
139 | size_t size; | 127 | size_t size; |
@@ -151,7 +139,7 @@ void FAST_FUNC encode_n_base64(char *fname, const char *text, size_t len, const | |||
151 | // encode the buffer we just read in | 139 | // encode the buffer we just read in |
152 | bb_uuencode(dst_buf, src_buf, size, bb_uuenc_tbl_base64); | 140 | bb_uuencode(dst_buf, src_buf, size, bb_uuenc_tbl_base64); |
153 | if (fname) { | 141 | if (fname) { |
154 | puts(eol); | 142 | puts(""); |
155 | } else { | 143 | } else { |
156 | src_buf += size; | 144 | src_buf += size; |
157 | len -= size; | 145 | len -= size; |
@@ -163,6 +151,21 @@ void FAST_FUNC encode_n_base64(char *fname, const char *text, size_t len, const | |||
163 | #undef src_buf | 151 | #undef src_buf |
164 | } | 152 | } |
165 | 153 | ||
154 | void FAST_FUNC printstr_base64(const char *text) | ||
155 | { | ||
156 | encode_n_base64(NULL, text, strlen(text)); | ||
157 | } | ||
158 | |||
159 | void FAST_FUNC printbuf_base64(const char *text, unsigned len) | ||
160 | { | ||
161 | encode_n_base64(NULL, text, len); | ||
162 | } | ||
163 | |||
164 | void FAST_FUNC printfile_base64(const char *fname) | ||
165 | { | ||
166 | encode_n_base64(fname, NULL, 0); | ||
167 | } | ||
168 | |||
166 | /* | 169 | /* |
167 | * get username and password from a file descriptor | 170 | * get username and password from a file descriptor |
168 | */ | 171 | */ |
diff --git a/mailutils/mail.h b/mailutils/mail.h index 4eb2bc2c0..b14228a4a 100644 --- a/mailutils/mail.h +++ b/mailutils/mail.h | |||
@@ -34,5 +34,6 @@ void get_cred_or_die(int fd) FAST_FUNC; | |||
34 | 34 | ||
35 | char *send_mail_command(const char *fmt, const char *param) FAST_FUNC; | 35 | char *send_mail_command(const char *fmt, const char *param) FAST_FUNC; |
36 | 36 | ||
37 | void encode_base64(char *fname, const char *text, const char *eol) FAST_FUNC; | 37 | void printbuf_base64(const char *buf, unsigned len) FAST_FUNC; |
38 | void encode_n_base64(char *fname, const char *text, size_t size, const char *eol) FAST_FUNC; | 38 | void printstr_base64(const char *buf) FAST_FUNC; |
39 | void printfile_base64(const char *fname) FAST_FUNC; | ||
diff --git a/mailutils/makemime.c b/mailutils/makemime.c index 577bcde39..7539d5134 100644 --- a/mailutils/makemime.c +++ b/mailutils/makemime.c | |||
@@ -234,7 +234,7 @@ int makemime_main(int argc UNUSED_PARAM, char **argv) | |||
234 | , G.opt_charset | 234 | , G.opt_charset |
235 | , bb_get_last_path_component_strip(*argv) | 235 | , bb_get_last_path_component_strip(*argv) |
236 | ); | 236 | ); |
237 | encode_base64(*argv++, (const char *)stdin, ""); | 237 | printfile_base64(*argv++); |
238 | } | 238 | } |
239 | 239 | ||
240 | // put multipart footer | 240 | // put multipart footer |
diff --git a/mailutils/sendmail.c b/mailutils/sendmail.c index 1dbaf595c..2fbceaad2 100644 --- a/mailutils/sendmail.c +++ b/mailutils/sendmail.c | |||
@@ -371,13 +371,13 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv) | |||
371 | // substitute placeholders | 371 | // substitute placeholders |
372 | plain_auth[0] = '\0'; | 372 | plain_auth[0] = '\0'; |
373 | plain_auth[1 + user_len] = '\0'; | 373 | plain_auth[1 + user_len] = '\0'; |
374 | encode_n_base64(NULL, plain_auth, 1 + user_len + 1 + pass_len, NULL); | 374 | printbuf_base64(plain_auth, 1 + user_len + 1 + pass_len); |
375 | free(plain_auth); | 375 | free(plain_auth); |
376 | } else if ((opts & OPT_am_mask) == OPT_am_login) { | 376 | } else if ((opts & OPT_am_mask) == OPT_am_login) { |
377 | smtp_check("AUTH LOGIN", 334); | 377 | smtp_check("AUTH LOGIN", 334); |
378 | encode_base64(NULL, G.user, NULL); | 378 | printstr_base64(G.user); |
379 | smtp_check("", 334); | 379 | smtp_check("", 334); |
380 | encode_base64(NULL, G.pass, NULL); | 380 | printstr_base64(G.pass); |
381 | } | 381 | } |
382 | smtp_check("", 235); | 382 | smtp_check("", 235); |
383 | } | 383 | } |