From 96769486e20fd5f1142cae0db2cbacef31dc75e9 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 17 Jun 2023 21:02:37 +0200 Subject: shell: move varcmp() to shell_common.h and use it in hush function old new delta unset_local_var - 112 +112 findvar 31 35 +4 set_vars_and_save_old 144 141 -3 helper_export_local 235 230 -5 set_local_var 425 416 -9 handle_changed_special_names 38 27 -11 builtin_unset 154 141 -13 builtin_getopts 404 391 -13 get_local_var_value 281 260 -21 get_ptr_to_local_var 71 45 -26 unset_local_var_len 139 - -139 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 1/8 up/down: 116/-240) Total: -124 bytes Signed-off-by: Denys Vlasenko --- shell/shell_common.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'shell/shell_common.c') diff --git a/shell/shell_common.c b/shell/shell_common.c index 1eca101b9..e5c2cefb3 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c @@ -22,6 +22,25 @@ const char defifsvar[] ALIGN1 = "IFS= \t\n"; const char defoptindvar[] ALIGN1 = "OPTIND=1"; +/* Compare two strings up to the first '=' or '\0'. */ +int FAST_FUNC varcmp(const char *p, const char *q) +{ + int c, d; + + while ((c = *p) == (d = *q)) { + if (c == '\0' || c == '=') + goto out; + p++; + q++; + } + if (c == '=') + c = '\0'; + if (d == '=') + d = '\0'; + out: + return c - d; +} + /* read builtin */ /* Needs to be interruptible: shell must handle traps and shell-special signals -- cgit v1.2.3-55-g6feb