]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/strutils: add ul_ prefix to startswith() and endswith()
authorKarel Zak <kzak@redhat.com>
Mon, 30 Jun 2025 09:15:30 +0000 (11:15 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 30 Jun 2025 09:15:30 +0000 (11:15 +0200)
Addresses: https://github.com/util-linux/util-linux/issues/3626
Signed-off-by: Karel Zak <kzak@redhat.com>
25 files changed:
disk-utils/partx.c
disk-utils/sfdisk.c
include/strutils.h
lib/canonicalize.c
lib/loopdev.c
lib/sysfs.c
lib/timeutils.c
libfdisk/src/utils.c
libmount/src/context_mount.c
libmount/src/context_umount.c
libmount/src/hook_idmap.c
libmount/src/optmap.c
libmount/src/optstr.c
libmount/src/tab.c
libmount/src/tab_parse.c
libmount/src/tab_update.c
libmount/src/utils.c
misc-utils/lsblk-properties.c
misc-utils/lsclocks.c
pam_lastlog2/src/pam_lastlog2.c
sys-utils/lscpu-cputype.c
sys-utils/mount.c
sys-utils/rtcwake.c
sys-utils/setpriv-landlock.c
text-utils/bits.c

index 4c8b1f09b09ada0fa3f929d89b6fa2af8b9ae4e5..347d5daad303d688f2da4d6778f5175689c4f56a 100644 (file)
@@ -953,7 +953,7 @@ int main(int argc, char **argv)
                        device = argv[optind];
                        wholedisk = xstrdup(argv[optind + 1]);
 
-                       if (device && wholedisk && !startswith(device, wholedisk))
+                       if (device && wholedisk && !ul_startswith(device, wholedisk))
                                errx(EXIT_FAILURE, _("partition and disk name do not match"));
                }
        } else if (optind == argc - 1) {
index 7f2f3deea2b0fcedb2acbacb98361a7873afdee1..ad9bbb3cf8ad8cb0d1dc1265694c24b227139000 100644 (file)
@@ -1794,12 +1794,12 @@ static void refresh_prompt_buffer(struct sfdisk *sf, const char *devname,
                if (!partname)
                        err(EXIT_FAILURE, _("failed to allocate partition name"));
 
-               if (!sf->prompt || !startswith(sf->prompt, partname)) {
+               if (!sf->prompt || !ul_startswith(sf->prompt, partname)) {
                        free(sf->prompt);
                        xasprintf(&sf->prompt,"%s: ", partname);
                }
                free(partname);
-       } else if (!sf->prompt || !startswith(sf->prompt, SFDISK_PROMPT)) {
+       } else if (!sf->prompt || !ul_startswith(sf->prompt, SFDISK_PROMPT)) {
                free(sf->prompt);
                sf->prompt = xstrdup(SFDISK_PROMPT);
        }
@@ -2024,7 +2024,7 @@ static int command_fdisk(struct sfdisk *sf, int argc, char **argv)
 
                        if (!rc) {              /* add partition */
                                if (!sf->interactive && !sf->quiet &&
-                                   (!sf->prompt || startswith(sf->prompt, SFDISK_PROMPT))) {
+                                   (!sf->prompt || ul_startswith(sf->prompt, SFDISK_PROMPT))) {
                                        refresh_prompt_buffer(sf, devname, next_partno, created);
                                        fputs(sf->prompt, stdout);
                                }
index e462040c80cc0386eb84c3b5e72cb5a965130e1b..2cea6e6e815059583e9faba8823b324ad5cf9d17 100644 (file)
@@ -269,7 +269,7 @@ extern int streq_paths(const char *a, const char *b);
 /*
  * Match string beginning.
  */
-static inline const char *startswith(const char *s, const char *prefix)
+static inline const char *ul_startswith(const char *s, const char *prefix)
 {
        size_t sz = prefix ? strlen(prefix) : 0;
 
@@ -295,7 +295,7 @@ static inline const char *startswith_no_case(const char *s, const char *prefix)
  */
 static inline const char *startswithpath(const char *s, const char *prefix)
 {
-       const char *p = startswith(s, prefix);
+       const char *p = ul_startswith(s, prefix);
 
        if (p && (*p == '/' || *p == '\0'))
                return p;
@@ -306,7 +306,7 @@ static inline const char *startswithpath(const char *s, const char *prefix)
 /*
  * Match string ending.
  */
-static inline const char *endswith(const char *s, const char *postfix)
+static inline const char *ul_endswith(const char *s, const char *postfix)
 {
        size_t sl = s ? strlen(s) : 0;
        size_t pl = postfix ? strlen(postfix) : 0;
index 0992a47472c3e3084af704dae36436cb65f9a739..6e70afe18a102397aeefa7bde920167cce52938e 100644 (file)
@@ -96,7 +96,7 @@ char *absolute_path(const char *path)
                return NULL;
 
        /* simple clean up */
-       if (startswith(path, "./"))
+       if (ul_startswith(path, "./"))
                path += 2;
        else if (strcmp(path, ".") == 0)
                path = NULL;
index 65efeb9ea1fc92683ff697db78f592f4115ea6f9..8c5beaeb7e1cda0c682ba2b71676236ae0c034a4 100644 (file)
@@ -695,7 +695,7 @@ int is_loopdev(const char *device)
                cn = canonicalize_path(name);
                if (cn)
                        p = stripoff_last_component(cn);
-               rc = p && startswith(p, "loop");
+               rc = p && ul_startswith(p, "loop");
                free(cn);
        }
 
index 951de6332a3300557c55a7acb85fb754bad6d4bb..c888617b77ff75f8d13ce0c68ad7c1f4c39e173d 100644 (file)
@@ -978,7 +978,7 @@ dev_t __sysfs_devname_to_devno(const char *prefix, const char *name, const char
        /*
         * Read from /sys/block/<parent>/<partition>/dev
         */
-       if (!dev && parent && startswith(name, parent)) {
+       if (!dev && parent && ul_startswith(name, parent)) {
                len = snprintf(buf, sizeof(buf),
                                "%s" _PATH_SYS_BLOCK "/%s/%s/dev",
                                prefix, _parent, _name);
index 2688f60d71c733cbeb119f5b08953d42e321b202..48e91d8dee23c72c18305cb2772639a8c2b7afbb 100644 (file)
@@ -118,7 +118,7 @@ static int parse_sec(const char *t, usec_t *usec)
                e += strspn(e, WHITESPACE);
 
                for (i = 0; i < ARRAY_SIZE(table); i++)
-                       if (startswith(e, table[i].suffix)) {
+                       if (ul_startswith(e, table[i].suffix)) {
                                usec_t k = (usec_t) z * table[i].usec;
 
                                for (; n > 0; n--)
@@ -278,7 +278,7 @@ static int parse_timestamp_reference(time_t x, const char *t, usec_t *usec)
                        goto finish;
 
                return -EINVAL;
-       } else if (endswith(t, " ago")) {
+       } else if (ul_endswith(t, " ago")) {
                char *z;
 
                z = strndup(t, strlen(t) - 4);
index a7c8bfa2e51e161ca94228096b7e3e304031f934..ef2663737dd705475e897ddd651c17ee792ceca7 100644 (file)
@@ -143,7 +143,7 @@ char *fdisk_partname(const char *dev, size_t partno)
 
        /* devfs kludge - note: fdisk partition names are not supposed
           to equal kernel names, so there is no reason to do this */
-       if (endswith(dev, "disc")) {
+       if (ul_endswith(dev, "disc")) {
                w -= 4;
                p = "part";
        }
index 24369857d97055f70741eb5b748a8ddc35c25151..9a1832550cf44efa3bc928f4c2c83b5ca07ed89c 100644 (file)
@@ -447,7 +447,7 @@ static int exec_helper(struct libmnt_context *cxt)
                }
                if (type
                    && strchr(type, '.')
-                   && !endswith(cxt->helper, type)) {
+                   && !ul_endswith(cxt->helper, type)) {
                        args[i++] = "-t";               /* 10 */
                        args[i++] = type;               /* 11 */
                }
@@ -1457,7 +1457,7 @@ static void join_err_mesgs(struct libmnt_context *cxt, char *buf, size_t bufsz)
 
                if (!bufsz)
                        break;
-               if (!startswith(*s, "e "))
+               if (!ul_startswith(*s, "e "))
                        continue;
                if (n) {
                        len = xstrncpy(buf, "; ", bufsz);
index 64a1d884ba0f7400cafa43a7f0ec06f2917e79e6..27319f77cf2da118f747886c33d194dffb6755e0 100644 (file)
@@ -725,7 +725,7 @@ static int exec_helper(struct libmnt_context *cxt)
                        args[i++] = "-r";                       /* 7 */
                if (type
                    && strchr(type, '.')
-                   && !endswith(cxt->helper, type)) {
+                   && !ul_endswith(cxt->helper, type)) {
                        args[i++] = "-t";                       /* 8 */
                        args[i++] = type;                       /* 9 */
                }
index e8c4cab5a06192a6082be9bfaccefa0fa601f410..5095de1f6acd6941872c42c9c3ecee763ad4b7d1 100644 (file)
@@ -434,15 +434,15 @@ static int hook_prepare_options(
                idmap_type_t map_type;
                uint32_t nsid = UINT_MAX, hostid = UINT_MAX, range = UINT_MAX;
 
-               if (startswith(tok, "b:")) {
+               if (ul_startswith(tok, "b:")) {
                        /* b:id-mount:id-host:id-range */
                        map_type = ID_TYPE_UIDGID;
                        tok += 2;
-               } else if (startswith(tok, "g:")) {
+               } else if (ul_startswith(tok, "g:")) {
                        /* g:id-mount:id-host:id-range */
                        map_type = ID_TYPE_GID;
                        tok += 2;
-               } else if (startswith(tok, "u:")) {
+               } else if (ul_startswith(tok, "u:")) {
                        /* u:id-mount:id-host:id-range */
                        map_type = ID_TYPE_UID;
                        tok += 2;
index d7569a0f0380ab15b29e6c01ce9bcf1af077eda7..4ea455d9445e7f27101b60621c610e8c6e0fc9ea 100644 (file)
@@ -250,7 +250,7 @@ const struct libmnt_optmap *mnt_optmap_get_entry(
 
                for (ent = map; ent && ent->name; ent++) {
                        if (ent->mask & MNT_PREFIX) {
-                               if (startswith(name, ent->name)) {
+                               if (ul_startswith(name, ent->name)) {
                                        if (mapent)
                                                *mapent = ent;
                                        return map;
index 30cd1af61667f3e5f1943b04a221c9f9b68c44fd..ac20d8755715a87dcbfcaaac9b3043812c4bf380 100644 (file)
@@ -914,7 +914,7 @@ int mnt_match_options(const char *optstr, const char *pattern)
 
                if (*name == '+')
                        name++, namesz--;
-               else if ((no = (startswith(name, "no") != NULL))) {
+               else if ((no = (ul_startswith(name, "no") != NULL))) {
                        name += 2, namesz -= 2;
                        if (!*name || *name == ',') {
                                match = 0;
index a5070f8240c2041b22e68380664bae6baadbcc4e..c8433674f9f4197b23afe3f4eec5b383b416c289 100644 (file)
@@ -1818,7 +1818,7 @@ struct libmnt_fs *mnt_table_get_fs_root(struct libmnt_table *tb,
 
                DBG(FS, ul_debugobj(fs, "source root: %s, source FS root: %s", root, src_root));
 
-               if (src_root && root && !startswith(root, src_root)) {
+               if (src_root && root && !ul_startswith(root, src_root)) {
                        if (strcmp(root, "/") == 0) {
                                free(root);
                                root = strdup(src_root);
@@ -1948,7 +1948,7 @@ int __mnt_table_is_fs_mounted(struct libmnt_table *tb, struct libmnt_fs *fstab_f
                        int flags = 0;
 
                        if (!mnt_fs_get_srcpath(fs) ||
-                           !startswith(mnt_fs_get_srcpath(fs), "/dev/loop"))
+                           !ul_startswith(mnt_fs_get_srcpath(fs), "/dev/loop"))
                                continue;       /* does not look like loopdev */
 
                        if (mnt_fs_get_option(fstab_fs, "offset", &val, &len) == 0) {
index e5db3e385cd8bc926e4ab4c60a43b26d71261765..3dd8538802e232f8680d22d5bf437ac304421d04 100644 (file)
@@ -395,7 +395,7 @@ static int mnt_parse_swaps_line(struct libmnt_fs *fs, const char *s)
        /* (1) source */
        p = unmangle(s, &s);
        if (p) {
-               char *x = (char *) endswith(p, PATH_DELETED_SUFFIX);
+               char *x = (char *) ul_endswith(p, PATH_DELETED_SUFFIX);
                if (x && *x)
                        *x = '\0';
        }
index a256edf85828a9ad9192696417cafbb5bd2047b6..3cb5b30f956c327cfeb65cefaeb3371eddc9fac3 100644 (file)
@@ -763,7 +763,7 @@ static int update_modify_target(struct libmnt_update *upd)
                        char *p;
                        const char *e;
 
-                       e = startswith(mnt_fs_get_target(fs), upd_source);
+                       e = ul_startswith(mnt_fs_get_target(fs), upd_source);
                        if (!e || (*e && *e != '/'))
                                continue;
                        if (*e == '/')
index 8c3151b7368f6d9a278db75eaf94e2b20282726a..46050ff51f5bbe517e464ca019847d08f715acde 100644 (file)
@@ -1393,7 +1393,7 @@ static int test_startswith(struct libmnt_test *ts __attribute__((unused)),
        char *optstr = argv[1];
        char *pattern = argv[2];
 
-       printf("%s\n", startswith(optstr, pattern) ? "YES" : "NOT");
+       printf("%s\n", ul_startswith(optstr, pattern) ? "YES" : "NOT");
        return 0;
 }
 
@@ -1406,7 +1406,7 @@ static int test_endswith(struct libmnt_test *ts __attribute__((unused)),
        char *optstr = argv[1];
        char *pattern = argv[2];
 
-       printf("%s\n", endswith(optstr, pattern) ? "YES" : "NOT");
+       printf("%s\n", ul_endswith(optstr, pattern) ? "YES" : "NOT");
        return 0;
 }
 
index 8c88025e2d39ffaec1bd5142e82cb7f0799c9ffd..1f80f3e18aee13934a55c0add4f774c5c5b81edd 100644 (file)
@@ -157,7 +157,7 @@ static struct lsblk_devprop *get_properties_by_udev(struct lsblk_device *ld)
                const char *name = udev_list_entry_get_name(le);
                size_t sz;
 
-               if (!name || !startswith(name,  LSBLK_UDEV_BYID_PREFIX))
+               if (!name || !ul_startswith(name,  LSBLK_UDEV_BYID_PREFIX))
                        continue;
                name += LSBLK_UDEV_BYID_PREFIXSZ;
                if (!*name)
index 24761bbd368613d874c5eb1583f7698f113ce151..435894182bc55dd8df973516a6df70b055b25238 100644 (file)
@@ -258,7 +258,7 @@ static int64_t get_namespace_offset(const char *name)
                line = strtok_r(tokstr, "\n", &saveptr);
                if (!line)
                        continue;
-               line = (char *) startswith(line, name);
+               line = (char *) ul_startswith(line, name);
                if (!line || line[0] != ' ')
                        continue;
 
index c3ca989c1cb9381cb06fe27c8d04cadc068b205f..0e3b8971949a129c1cca9300ea03dd6ed93cad6b 100644 (file)
@@ -98,9 +98,9 @@ _pam_parse_args (pam_handle_t *pamh,
                        ctrl |= LASTLOG2_DEBUG;
                else if (strcmp (*argv, "silent") == 0)
                        ctrl |= LASTLOG2_QUIET;
-               else if ((str = startswith (*argv, "database=")) != NULL)
+               else if ((str = ul_startswith (*argv, "database=")) != NULL)
                        lastlog2_path = str;
-               else if ((str = startswith (*argv, "silent_if=")) != NULL) {
+               else if ((str = ul_startswith (*argv, "silent_if=")) != NULL) {
                        const void *void_str = NULL;
                        const char *service;
                        if ((pam_get_item (pamh, PAM_SERVICE, &void_str) != PAM_SUCCESS) ||
@@ -143,7 +143,7 @@ write_login_data (pam_handle_t *pamh, int ctrl, const char *user)
                tty = void_str;
 
        /* strip leading "/dev/" from tty. */
-       const char *str = startswith(tty, "/dev/");
+       const char *str = ul_startswith(tty, "/dev/");
        if (str != NULL)
                tty = str;
 
index 50eec6a373e41a7cee26df01582bf4c883717baf..d741ce60024fa0a2a1d25670ae626da705362605 100644 (file)
@@ -966,7 +966,7 @@ int lscpu_read_vulnerabilities(struct lscpu_cxt *cxt)
 
                /* Description */
                vu->text = str;
-               p = (char *) startswith(vu->text, "Mitigation");
+               p = (char *) ul_startswith(vu->text, "Mitigation");
                if (p) {
                        *p = ';';
                        strrem(vu->text, ':');
index 875d249b477280de3b0114f989ff4689d118db66..b4b8fb63a53e2ea3035b2c6584a792a75dd45e71 100644 (file)
@@ -393,17 +393,17 @@ static size_t libmount_mesgs(struct libmnt_context *cxt, char type)
        UL_STRV_FOREACH(s, mesgs) {
                switch (type) {
                case 'e':
-                       if (!startswith(*s, "e "))
+                       if (!ul_startswith(*s, "e "))
                                break;
                        fprintf(stderr, "      * %s\n", (*s) + 2);
                        break;
                case 'w':
-                       if (!startswith(*s, "w "))
+                       if (!ul_startswith(*s, "w "))
                                break;
                        fprintf(stdout, "      * %s\n", (*s) + 2);
                        break;
                case 'i':
-                       if (!startswith(*s, "i "))
+                       if (!ul_startswith(*s, "i "))
                                break;
                        fprintf(stdout, "      * %s\n", (*s) + 2);
                        break;
index d01f5ed343c9b86a262e0b70f77567027f6ce1b7..45cbe9bc689e0d0f166693ad027c72e42e9a86fa 100644 (file)
@@ -138,7 +138,7 @@ static int is_wakeup_enabled(const char *devname)
        FILE    *f;
        size_t  skip = 0;
 
-       if (startswith(devname, "/dev/"))
+       if (ul_startswith(devname, "/dev/"))
                skip = 5;
        snprintf(buf, sizeof buf, SYS_WAKEUP_PATH_TEMPLATE, devname + skip);
        f = fopen(buf, "r");
@@ -402,7 +402,7 @@ static int open_dev_rtc(const char *devname)
        int fd;
        char *devpath = NULL;
 
-       if (startswith(devname, "/dev"))
+       if (ul_startswith(devname, "/dev"))
                devpath = xstrdup(devname);
        else
                xasprintf(&devpath, "/dev/%s", devname);
index efbacafd0b1b9b508577ad375337a3216bc2da4a..1adea773f321ab69f7b0dab160ad7911d71b6d05 100644 (file)
@@ -120,7 +120,7 @@ void parse_landlock_access(struct setpriv_landlock_opts *opts, const char *str)
                return;
        }
 
-       type = startswith(str, "fs:");
+       type = ul_startswith(str, "fs:");
        if (type)
                opts->access_fs |= parse_landlock_fs_access(type);
 }
@@ -132,7 +132,7 @@ void parse_landlock_rule(struct setpriv_landlock_opts *opts, const char *str)
        char *accesses_part;
        int parent_fd;
 
-       accesses = startswith(str, "path-beneath:");
+       accesses = ul_startswith(str, "path-beneath:");
        if (!accesses)
                errx(EXIT_FAILURE, _("invalid landlock rule: %s"), str);
        path = strchr(accesses, ':');
index aca4306ee1e2c32da83d7da0cbc7e25f050db9dd..97a77a82f72b3bedc34f4df8923ecf7122c03bc9 100644 (file)
@@ -39,16 +39,16 @@ static void parse_mask_or_list(const char *cmdline_arg,
        arg = cmdline_arg;
 
        /* strip optional operator first */
-       if (startswith(arg, "&")) {
+       if (ul_startswith(arg, "&")) {
                bitwise_op = '&';
                arg++;
-       } else if (startswith(arg, "^")) {
+       } else if (ul_startswith(arg, "^")) {
                bitwise_op = '^';
                arg++;
-       } else if (startswith(arg, "~")) {
+       } else if (ul_startswith(arg, "~")) {
                bitwise_op = '~';
                arg++;
-       } else if (startswith(arg, "|")) {
+       } else if (ul_startswith(arg, "|")) {
                arg++;
        }
 
@@ -56,8 +56,8 @@ static void parse_mask_or_list(const char *cmdline_arg,
        if (bits == NULL)
                errx(EXIT_FAILURE, _("error: cannot allocate bit mask"));
 
-       if (startswith(arg, ",") || startswith(arg, "0x")) {
-               if (startswith(arg, ","))
+       if (ul_startswith(arg, ",") || ul_startswith(arg, "0x")) {
+               if (ul_startswith(arg, ","))
                        arg++;
                if (cpumask_parse(arg, bits, size) < 0)
                        errx(EXIT_FAILURE, _("error: invalid bit mask: %s"), cmdline_arg);