diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2025-08-02 07:18:56 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2025-08-02 07:18:56 +0200 |
| commit | 91d8b4eb5c770dfcc05f74dd0bd7b3fabc236530 (patch) | |
| tree | a0a6d5c8e5b08e61b1241be8cbe19d27b249833f /modutils | |
| parent | 2d7ff2c909c6dce95a8780d00e2089f0c507dd25 (diff) | |
ftpd: code shrink, move replace_char() to libbb
function old new delta
modprobe_main 803 804 +1
escape_text 127 122 -5
replace 18 - -18
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 1/-23) Total: -22 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'modutils')
| -rw-r--r-- | modutils/modprobe-small.c | 21 | ||||
| -rw-r--r-- | modutils/modprobe.c | 2 | ||||
| -rw-r--r-- | modutils/modutils.c | 9 | ||||
| -rw-r--r-- | modutils/modutils.h | 1 |
4 files changed, 7 insertions, 26 deletions
diff --git a/modutils/modprobe-small.c b/modutils/modprobe-small.c index 77e42e3fb..31a215a29 100644 --- a/modutils/modprobe-small.c +++ b/modutils/modprobe-small.c @@ -186,15 +186,6 @@ static char* find_keyword(char *ptr, size_t len, const char *word) return NULL; } -static void replace(char *s, char what, char with) -{ - while (*s) { - if (what == *s) - *s = with; - ++s; - } -} - static char *filename2modname(const char *filename, char *modname) { int i; @@ -230,7 +221,7 @@ static char* str_2_list(const char *str) dst[len] = '\0'; memcpy(dst, str, len); //TODO: protect against 2+ spaces: "word word" - replace(dst, ' ', '\0'); + replace_char(dst, ' ', '\0'); return dst; } @@ -369,14 +360,14 @@ static int parse_module(module_info *info, const char *pathname) } bksp(); /* remove last ' ' */ info->aliases = copy_stringbuf(); - replace(info->aliases, '-', '_'); + replace_char(info->aliases, '-', '_'); /* "dependency1 depandency2" */ reset_stringbuf(); ptr = find_keyword(module_image, len, "depends="); if (ptr && *ptr) { - replace(ptr, ',', ' '); - replace(ptr, '-', '_'); + replace_char(ptr, ',', ' '); + replace_char(ptr, '-', '_'); dbg2_error_msg("dep:'%s'", ptr); append(ptr); } @@ -707,7 +698,7 @@ static int process_module(char *name, const char *cmdline_options) dbg1_error_msg("process_module('%s','%s')", name, cmdline_options); - replace(name, '-', '_'); + replace_char(name, '-', '_'); dbg1_error_msg("already_loaded:%d is_remove:%d", already_loaded(name), is_remove); @@ -735,7 +726,7 @@ static int process_module(char *name, const char *cmdline_options) char *opt_filename = xasprintf("/etc/modules/%s", name); options = xmalloc_open_read_close(opt_filename, NULL); if (options) - replace(options, '\n', ' '); + replace_char(options, '\n', ' '); #if ENABLE_FEATURE_CMDLINE_MODULE_OPTIONS if (cmdline_options) { /* NB: cmdline_options always have one leading ' ' diff --git a/modutils/modprobe.c b/modutils/modprobe.c index 543f53e99..f890abe53 100644 --- a/modutils/modprobe.c +++ b/modutils/modprobe.c @@ -579,7 +579,7 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv) parser_t *p = config_open2(CONFIG_DEFAULT_DEPMOD_FILE, xfopen_for_read); for (i = 0; argv[i]; i++) - replace(argv[i], '-', '_'); + replace_char(argv[i], '-', '_'); while (config_read(p, tokens, 2, 1, "# \t", PARSE_NORMAL)) { colon = last_char_is(tokens[0], ':'); diff --git a/modutils/modutils.c b/modutils/modutils.c index cbff20961..862f71f57 100644 --- a/modutils/modutils.c +++ b/modutils/modutils.c @@ -69,15 +69,6 @@ void FAST_FUNC moddb_free(module_db *db) } } -void FAST_FUNC replace(char *s, char what, char with) -{ - while (*s) { - if (what == *s) - *s = with; - ++s; - } -} - int FAST_FUNC string_to_llist(char *string, llist_t **llist, const char *delim) { char *tok; diff --git a/modutils/modutils.h b/modutils/modutils.h index 4a702e97c..9b05116d1 100644 --- a/modutils/modutils.h +++ b/modutils/modutils.h @@ -47,7 +47,6 @@ module_entry *moddb_get(module_db *db, const char *s) FAST_FUNC; module_entry *moddb_get_or_create(module_db *db, const char *s) FAST_FUNC; void moddb_free(module_db *db) FAST_FUNC; -void replace(char *s, char what, char with) FAST_FUNC; int string_to_llist(char *string, llist_t **llist, const char *delim) FAST_FUNC; char *filename2modname(const char *filename, char *modname) FAST_FUNC; #if ENABLE_FEATURE_CMDLINE_MODULE_OPTIONS |
