mail: move "opts" from globals

function                                             old     new   delta
popmaildir_main                                      812     823     +11
sendmail_main                                       1295    1301      +6
makemime_main                                        291     288      -3
parse                                                970     966      -4
reformime_main                                       107     100      -7
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/3 up/down: 17/-14)              Total: 3 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2020-12-17 12:24:50 +01:00
parent 91e330a53f
commit 25b2680056
6 changed files with 15 additions and 15 deletions

View File

@ -72,12 +72,12 @@ void FAST_FUNC launch_helper(const char **argv)
char* FAST_FUNC send_mail_command(const char *fmt, const char *param) char* FAST_FUNC send_mail_command(const char *fmt, const char *param)
{ {
char *msg; char *msg;
if (timeout) if (G.timeout)
alarm(timeout); alarm(G.timeout);
msg = (char*)fmt; msg = (char*)fmt;
if (fmt) { if (fmt) {
msg = xasprintf(fmt, param); msg = xasprintf(fmt, param);
if (verbose) if (G.verbose)
bb_error_msg("send:'%s'", msg); bb_error_msg("send:'%s'", msg);
printf("%s\r\n", msg); printf("%s\r\n", msg);
} }

View File

@ -11,7 +11,6 @@ struct globals {
pid_t helper_pid; pid_t helper_pid;
unsigned timeout; unsigned timeout;
unsigned verbose; unsigned verbose;
unsigned opts;
char *user; char *user;
char *pass; char *pass;
FILE *fp0; // initial stdin FILE *fp0; // initial stdin
@ -19,9 +18,6 @@ struct globals {
}; };
#define G (*ptr_to_globals) #define G (*ptr_to_globals)
#define timeout (G.timeout )
#define verbose (G.verbose )
#define opts (G.opts )
#define INIT_G() do { \ #define INIT_G() do { \
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
G.opt_charset = (char *)CONFIG_FEATURE_MIME_CHARSET; \ G.opt_charset = (char *)CONFIG_FEATURE_MIME_CHARSET; \

View File

@ -173,6 +173,7 @@ Content-Transfer-Encoding: 7bit
int makemime_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int makemime_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int makemime_main(int argc UNUSED_PARAM, char **argv) int makemime_main(int argc UNUSED_PARAM, char **argv)
{ {
unsigned opts;
llist_t *opt_headers = NULL, *l; llist_t *opt_headers = NULL, *l;
const char *opt_output; const char *opt_output;
const char *content_type = "application/octet-stream"; const char *content_type = "application/octet-stream";

View File

@ -71,7 +71,7 @@ static void pop3_checkr(const char *fmt, const char *param, char **ret)
char *answer = xmalloc_fgetline(stdin); char *answer = xmalloc_fgetline(stdin);
if (answer && '+' == answer[0]) { if (answer && '+' == answer[0]) {
free(msg); free(msg);
if (timeout) if (G.timeout)
alarm(0); alarm(0);
if (ret) { if (ret) {
// skip "+OK " // skip "+OK "
@ -92,6 +92,7 @@ static void pop3_check(const char *fmt, const char *param)
int popmaildir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int popmaildir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int popmaildir_main(int argc UNUSED_PARAM, char **argv) int popmaildir_main(int argc UNUSED_PARAM, char **argv)
{ {
unsigned opts;
char *buf; char *buf;
unsigned nmsg; unsigned nmsg;
char *hostname; char *hostname;
@ -128,7 +129,7 @@ int popmaildir_main(int argc UNUSED_PARAM, char **argv)
opts = getopt32(argv, "^" opts = getopt32(argv, "^"
"bdmVcasTkt:+" "R:+Z:L:+H:+" IF_FEATURE_POPMAILDIR_DELIVERY("M:F:") "bdmVcasTkt:+" "R:+Z:L:+H:+" IF_FEATURE_POPMAILDIR_DELIVERY("M:F:")
"\0" "-1:dd", "\0" "-1:dd",
&timeout, NULL, NULL, NULL, &opt_nlines &G.timeout, NULL, NULL, NULL, &opt_nlines
IF_FEATURE_POPMAILDIR_DELIVERY(, &delivery, &delivery) // we treat -M and -F the same IF_FEATURE_POPMAILDIR_DELIVERY(, &delivery, &delivery) // we treat -M and -F the same
); );
//argc -= optind; //argc -= optind;

View File

@ -166,7 +166,7 @@ static int parse(const char *boundary, char **argv)
else else
filename = bb_get_last_path_component_strip(xstrdup(filename)); filename = bb_get_last_path_component_strip(xstrdup(filename));
if (opts & OPT_X) { if (option_mask32 & OPT_X) {
int fd[2]; int fd[2];
/* start external helper */ /* start external helper */
@ -219,7 +219,7 @@ static int parse(const char *boundary, char **argv)
fclose(fp); fclose(fp);
/* Wait for child */ /* Wait for child */
if (opts & OPT_X) { if (option_mask32 & OPT_X) {
int rc; int rc;
signal(SIGPIPE, SIG_DFL); signal(SIGPIPE, SIG_DFL);
rc = (wait4pid(pid) & 0xff); rc = (wait4pid(pid) & 0xff);
@ -275,6 +275,7 @@ Usage: reformime [options]
int reformime_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int reformime_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int reformime_main(int argc UNUSED_PARAM, char **argv) int reformime_main(int argc UNUSED_PARAM, char **argv)
{ {
unsigned opts;
const char *opt_prefix = ""; const char *opt_prefix = "";
INIT_G(); INIT_G();

View File

@ -104,7 +104,7 @@
static void send_r_n(const char *s) static void send_r_n(const char *s)
{ {
if (verbose) if (G.verbose)
bb_error_msg("send:'%s'", s); bb_error_msg("send:'%s'", s);
printf("%s\r\n", s); printf("%s\r\n", s);
} }
@ -120,7 +120,7 @@ static int smtp_checkp(const char *fmt, const char *param, int code)
// if code != -1 then checks whether the number equals the code // if code != -1 then checks whether the number equals the code
// if not equal -> die saying msg // if not equal -> die saying msg
while ((answer = xmalloc_fgetline(stdin)) != NULL) { while ((answer = xmalloc_fgetline(stdin)) != NULL) {
if (verbose) if (G.verbose)
bb_error_msg("recv:'%.*s'", (int)(strchrnul(answer, '\r') - answer), answer); bb_error_msg("recv:'%.*s'", (int)(strchrnul(answer, '\r') - answer), answer);
if (strlen(answer) <= 3 || '-' != answer[3]) if (strlen(answer) <= 3 || '-' != answer[3])
break; break;
@ -128,7 +128,7 @@ static int smtp_checkp(const char *fmt, const char *param, int code)
} }
if (answer) { if (answer) {
int n = atoi(answer); int n = atoi(answer);
if (timeout) if (G.timeout)
alarm(0); alarm(0);
free(answer); free(answer);
if (-1 == code || n == code) { if (-1 == code || n == code) {
@ -223,6 +223,7 @@ static void rcptto_list(const char *list)
int sendmail_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int sendmail_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int sendmail_main(int argc UNUSED_PARAM, char **argv) int sendmail_main(int argc UNUSED_PARAM, char **argv)
{ {
unsigned opts;
char *opt_connect; char *opt_connect;
char *opt_from = NULL; char *opt_from = NULL;
char *s; char *s;
@ -276,7 +277,7 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
// -v is a counter, -H and -S are mutually exclusive, -a is a list // -v is a counter, -H and -S are mutually exclusive, -a is a list
"vv:H--S:S--H", "vv:H--S:S--H",
&opt_from, NULL, &opt_from, NULL,
&timeout, &opt_connect, &opt_connect, &list, &verbose &G.timeout, &opt_connect, &opt_connect, &list, &G.verbose
); );
//argc -= optind; //argc -= optind;
argv += optind; argv += optind;