diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2026-02-05 13:36:27 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2026-02-05 13:36:27 +0100 |
| commit | fddd93edbdbf8c5afbfdb3c01d82e082a8a82d1a (patch) | |
| tree | bc67c4cd3acea69333eb7bb4d8d4d904d5d6027a /util-linux/mount.c | |
| parent | 3d572a8cc3d71b43877db2776882e91303a0532d (diff) | |
| download | busybox-w32-fddd93edbdbf8c5afbfdb3c01d82e082a8a82d1a.tar.gz busybox-w32-fddd93edbdbf8c5afbfdb3c01d82e082a8a82d1a.tar.bz2 busybox-w32-fddd93edbdbf8c5afbfdb3c01d82e082a8a82d1a.zip | |
libbb: introduce and use xasprintf_inplace()
function old new delta
xasprintf_and_free - 49 +49
watch_main 269 282 +13
singlemount 1313 1315 +2
append_mount_options 157 149 -8
ip_port_str 122 112 -10
lsblk_main 869 858 -11
add_cmd 1178 1167 -11
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/4 up/down: 64/-40) Total: 24 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/mount.c')
| -rw-r--r-- | util-linux/mount.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/util-linux/mount.c b/util-linux/mount.c index d0f0ae1ad..d0d109c09 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
| @@ -556,27 +556,33 @@ static int verbose_mount(const char *source, const char *target, | |||
| 556 | #endif | 556 | #endif |
| 557 | 557 | ||
| 558 | // Append mount options to string | 558 | // Append mount options to string |
| 559 | // ("merge two comma-separated lists" is a good candidate for libbb!) | ||
| 559 | static void append_mount_options(char **oldopts, const char *newopts) | 560 | static void append_mount_options(char **oldopts, const char *newopts) |
| 560 | { | 561 | { |
| 561 | if (*oldopts && **oldopts) { | 562 | if (*oldopts && **oldopts) { |
| 563 | //TODO: do this unconditionally? | ||
| 564 | //this way, newopts of "opt1,opt2,opt1" | ||
| 565 | //will be de-duped into "opt1,opt2" in _both_ cases | ||
| 566 | //(whether or now old opts are empty) | ||
| 567 | //the only modification needed is to not prepend extra comma | ||
| 568 | //when old opts is "". | ||
| 562 | // Do not insert options which are already there | 569 | // Do not insert options which are already there |
| 563 | while (newopts[0]) { | 570 | while (*newopts) { |
| 564 | char *p; | 571 | char *p; |
| 565 | int len; | 572 | int len; |
| 566 | 573 | ||
| 574 | //if (*newopts == ',') { newopts++; continue; } | ||
| 567 | len = strchrnul(newopts, ',') - newopts; | 575 | len = strchrnul(newopts, ',') - newopts; |
| 568 | p = *oldopts; | 576 | p = *oldopts; |
| 569 | while (1) { | 577 | while (1) { |
| 570 | if (!strncmp(p, newopts, len) | 578 | if (strncmp(p, newopts, len) == 0 |
| 571 | && (p[len] == ',' || p[len] == '\0')) | 579 | && (p[len] == ',' || p[len] == '\0')) |
| 572 | goto skip; | 580 | goto skip; |
| 573 | p = strchr(p,','); | 581 | p = strchr(p, ','); |
| 574 | if (!p) break; | 582 | if (!p) break; |
| 575 | p++; | 583 | p++; |
| 576 | } | 584 | } |
| 577 | p = xasprintf("%s,%.*s", *oldopts, len, newopts); | 585 | xasprintf_inplace(*oldopts, "%s,%.*s", *oldopts, len, newopts); |
| 578 | free(*oldopts); | ||
| 579 | *oldopts = p; | ||
| 580 | skip: | 586 | skip: |
| 581 | newopts += len; | 587 | newopts += len; |
| 582 | while (*newopts == ',') newopts++; | 588 | while (*newopts == ',') newopts++; |
| @@ -2065,12 +2071,11 @@ static int singlemount(struct mntent *mp, int ignore_busy) | |||
| 2065 | if (!is_prefixed_with(filteropts, ",ip="+1) | 2071 | if (!is_prefixed_with(filteropts, ",ip="+1) |
| 2066 | && !strstr(filteropts, ",ip=") | 2072 | && !strstr(filteropts, ",ip=") |
| 2067 | ) { | 2073 | ) { |
| 2068 | char *dotted, *ip; | 2074 | char *ip; |
| 2069 | // Insert "ip=..." option into options | 2075 | // Insert "ip=..." option into options |
| 2070 | dotted = xmalloc_sockaddr2dotted_noport(&lsa->u.sa); | 2076 | ip = xmalloc_sockaddr2dotted_noport(&lsa->u.sa); |
| 2071 | if (ENABLE_FEATURE_CLEAN_UP) free(lsa); | 2077 | if (ENABLE_FEATURE_CLEAN_UP) free(lsa); |
| 2072 | ip = xasprintf("ip=%s", dotted); | 2078 | xasprintf_inplace(ip, "ip=%s", ip); |
| 2073 | if (ENABLE_FEATURE_CLEAN_UP) free(dotted); | ||
| 2074 | // Note: IPv6 scoped addresses ("host%iface", see RFC 4007) should be | 2079 | // Note: IPv6 scoped addresses ("host%iface", see RFC 4007) should be |
| 2075 | // handled by libc in getnameinfo() (inside xmalloc_sockaddr2dotted_noport()). | 2080 | // handled by libc in getnameinfo() (inside xmalloc_sockaddr2dotted_noport()). |
| 2076 | // Currently, glibc does not support that (has no NI_NUMERICSCOPE), | 2081 | // Currently, glibc does not support that (has no NI_NUMERICSCOPE), |
