From 19358cc31317dca4642417066c1445ce00438e18 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 5 Aug 2018 15:42:29 +0200 Subject: ash,hush: fold shell_builtin_read() way-too-many params into a struct param function old new delta getoptscmd 587 584 -3 readcmd 240 224 -16 shell_builtin_read 1426 1399 -27 builtin_read 210 182 -28 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/4 up/down: 0/-74) Total: -74 bytes Signed-off-by: Denys Vlasenko --- shell/hush.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'shell/hush.c') diff --git a/shell/hush.c b/shell/hush.c index 4c8814a01..3c19bceaa 100644 --- a/shell/hush.c +++ b/shell/hush.c @@ -10500,40 +10500,29 @@ static int FAST_FUNC builtin_type(char **argv) static int FAST_FUNC builtin_read(char **argv) { const char *r; - char *opt_n = NULL; - char *opt_p = NULL; - char *opt_t = NULL; - char *opt_u = NULL; - char *opt_d = NULL; /* optimized out if !BASH */ - const char *ifs; - int read_flags; + struct builtin_read_params params; + + memset(¶ms, 0, sizeof(params)); /* "!": do not abort on errors. * Option string must start with "sr" to match BUILTIN_READ_xxx */ - read_flags = getopt32(argv, + params.read_flags = getopt32(argv, #if BASH_READ_D - "!srn:p:t:u:d:", &opt_n, &opt_p, &opt_t, &opt_u, &opt_d + "!srn:p:t:u:d:", ¶ms.opt_n, ¶ms.opt_p, ¶ms.opt_t, ¶ms.opt_u, ¶ms.opt_d #else - "!srn:p:t:u:", &opt_n, &opt_p, &opt_t, &opt_u + "!srn:p:t:u:", ¶ms.opt_n, ¶ms.opt_p, ¶ms.opt_t, ¶ms.opt_u #endif ); - if (read_flags == (uint32_t)-1) + if ((uint32_t)params.read_flags == (uint32_t)-1) return EXIT_FAILURE; argv += optind; - ifs = get_local_var_value("IFS"); /* can be NULL */ + params.argv = argv; + params.setvar = set_local_var_from_halves; + params.ifs = get_local_var_value("IFS"); /* can be NULL */ again: - r = shell_builtin_read(set_local_var_from_halves, - argv, - ifs, - read_flags, - opt_n, - opt_p, - opt_t, - opt_u, - opt_d - ); + r = shell_builtin_read(¶ms); if ((uintptr_t)r == 1 && errno == EINTR) { unsigned sig = check_and_run_traps(); -- cgit v1.2.3