sendfile: code shrink
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 31 Jul 2018 15:30:08 +0000 (17:30 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 31 Jul 2018 15:30:08 +0000 (17:30 +0200)
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>
mailutils/mail.c
mailutils/mail.h
mailutils/makemime.c
mailutils/sendmail.c

index 2ad959f7deff09d16e9358fe85a14bab74d4ab79..6726654f78d261ee06f76591be45d8f6b7d081ba 100644 (file)
@@ -107,18 +107,7 @@ static char* FAST_FUNC parse_url(char *url, char **user, char **pass)
 }
 */
 
-void FAST_FUNC encode_base64(char *fname, const char *text, const char *eol)
-{
-       size_t len = len;
-       if (text) {
-               // though we do not call uuencode(NULL, NULL) explicitly
-               // still we do not want to break things suddenly
-               len = strlen(text);
-       }
-       encode_n_base64(fname, text, len, eol);
-}
-
-void FAST_FUNC encode_n_base64(char *fname, const char *text, size_t len, const char *eol)
+static void encode_n_base64(const char *fname, const char *text, size_t len)
 {
        enum {
                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
        char dst_buf[DST_BUF_SIZE + 1];
 
        if (fname) {
-               fp = (NOT_LONE_DASH(fname)) ? xfopen_for_read(fname) : (FILE *)text;
+               fp = (NOT_LONE_DASH(fname)) ? xfopen_for_read(fname) : stdin;
                src_buf = src;
-       } else if (!text)
-               return;
+       }
 
        while (1) {
                size_t size;
@@ -151,7 +139,7 @@ void FAST_FUNC encode_n_base64(char *fname, const char *text, size_t len, const
                // encode the buffer we just read in
                bb_uuencode(dst_buf, src_buf, size, bb_uuenc_tbl_base64);
                if (fname) {
-                       puts(eol);
+                       puts("");
                } else {
                        src_buf += size;
                        len -= size;
@@ -163,6 +151,21 @@ void FAST_FUNC encode_n_base64(char *fname, const char *text, size_t len, const
 #undef src_buf
 }
 
+void FAST_FUNC printstr_base64(const char *text)
+{
+       encode_n_base64(NULL, text, strlen(text));
+}
+
+void FAST_FUNC printbuf_base64(const char *text, unsigned len)
+{
+       encode_n_base64(NULL, text, len);
+}
+
+void FAST_FUNC printfile_base64(const char *fname)
+{
+       encode_n_base64(fname, NULL, 0);
+}
+
 /*
  * get username and password from a file descriptor
  */
index 4eb2bc2c0183cf3513add662a233a7f4a2241af2..b14228a4a5e34fc23e9186f8fe6855d000cb58eb 100644 (file)
@@ -34,5 +34,6 @@ void get_cred_or_die(int fd) FAST_FUNC;
 
 char *send_mail_command(const char *fmt, const char *param) FAST_FUNC;
 
-void encode_base64(char *fname, const char *text, const char *eol) FAST_FUNC;
-void encode_n_base64(char *fname, const char *text, size_t size, const char *eol) FAST_FUNC;
+void printbuf_base64(const char *buf, unsigned len) FAST_FUNC;
+void printstr_base64(const char *buf) FAST_FUNC;
+void printfile_base64(const char *fname) FAST_FUNC;
index 577bcde3992ad3ed27b2cd7f348e1a12fd661be2..7539d5134fc55920cff28614f41cdf72390c058b 100644 (file)
@@ -234,7 +234,7 @@ int makemime_main(int argc UNUSED_PARAM, char **argv)
                        , G.opt_charset
                        , bb_get_last_path_component_strip(*argv)
                );
-               encode_base64(*argv++, (const char *)stdin, "");
+               printfile_base64(*argv++);
        }
 
        // put multipart footer
index 1dbaf595cb257d119b50a00bf902e459bb4ac6a8..2fbceaad2a45ae95d5db5b96e20c3c41e056d1d6 100644 (file)
@@ -371,13 +371,13 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
                        // substitute placeholders
                        plain_auth[0] = '\0';
                        plain_auth[1 + user_len] = '\0';
-                       encode_n_base64(NULL, plain_auth, 1 + user_len + 1 + pass_len, NULL);
+                       printbuf_base64(plain_auth, 1 + user_len + 1 + pass_len);
                        free(plain_auth);
                } else if ((opts & OPT_am_mask) == OPT_am_login) {
                        smtp_check("AUTH LOGIN", 334);
-                       encode_base64(NULL, G.user, NULL);
+                       printstr_base64(G.user);
                        smtp_check("", 334);
-                       encode_base64(NULL, G.pass, NULL);
+                       printstr_base64(G.pass);
                }
                smtp_check("", 235);
        }