libbb: introduce and use is_prefixed_with()
authorDenys Vlasenko <vda.linux@googlemail.com>
Thu, 12 Mar 2015 16:48:34 +0000 (17:48 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 12 Mar 2015 16:48:34 +0000 (17:48 +0100)
function                                             old     new   delta
is_prefixed_with                                       -      18     +18
complete_username                                     78      77      -1
man_main                                             737     735      -2
fsck_device                                          429     427      -2
unpack_ar_archive                                     80      76      -4
strip_unsafe_prefix                                  105     101      -4
singlemount                                         1054    1050      -4
rtc_adjtime_is_utc                                    90      86      -4
resolve_mount_spec                                    88      84      -4
parse_one_line                                      1029    1025      -4
parse_conf                                          1460    1456      -4
may_wakeup                                            83      79      -4
loadkmap_main                                        219     215      -4
get_irqs_from_stat                                   103      99      -4
get_header_cpio                                      913     909      -4
findfs_main                                           79      75      -4
fbsplash_main                                       1230    1226      -4
load_crontab                                         776     771      -5
expand_vars_to_list                                 1151    1146      -5
date_main                                            881     876      -5
skip_dev_pfx                                          30      24      -6
make_device                                         2199    2193      -6
complete_cmd_dir_file                                773     767      -6
run_applet_and_exit                                  715     708      -7
uudecode_main                                        321     313      -8
pwdx_main                                            197     189      -8
execute                                              568     560      -8
i2cdetect_main                                      1186    1176     -10
procps_scan                                         1242    1230     -12
procps_read_smaps                                   1017    1005     -12
process_module                                       746     734     -12
patch_main                                          1903    1891     -12
nfsmount                                            3572    3560     -12
stack_machine                                        126     112     -14
process_timer_stats                                  449     435     -14
match_fstype                                         111      97     -14
do_ipaddr                                           1344    1330     -14
open_list_and_close                                  359     343     -16
get_header_tar                                      1795    1779     -16
prepend_new_eth_table                                340     323     -17
fsck_main                                           1811    1794     -17
find_iface_state                                      56      38     -18
dnsd_main                                           1321    1303     -18
base_device                                          179     158     -21
find_keyword                                         104      82     -22
handle_incoming_and_exit                            2785    2762     -23
parse_and_put_prompt                                 774     746     -28
modinfo                                              347     317     -30
find_action                                          204     171     -33
update_passwd                                       1470    1436     -34
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/49 up/down: 18/-540)         Total: -522 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
51 files changed:
archival/libarchive/get_header_cpio.c
archival/libarchive/get_header_tar.c
archival/libarchive/unpack_ar_archive.c
archival/libarchive/unsafe_prefix.c
console-tools/loadkmap.c
coreutils/date.c
coreutils/uudecode.c
e2fsprogs/fsck.c
editors/patch.c
include/libbb.h
libbb/appletlib.c
libbb/compare_string_array.c
libbb/lineedit.c
libbb/match_fstype.c
libbb/procps.c
libbb/rtc.c
libbb/skip_whitespace.c
libbb/update_passwd.c
libbb/xconnect.c
miscutils/crond.c
miscutils/dc.c
miscutils/devfsd.c
miscutils/fbsplash.c
miscutils/i2c_tools.c
miscutils/last.c
miscutils/man.c
modutils/depmod.c
modutils/modinfo.c
modutils/modprobe-small.c
modutils/modprobe.c
modutils/modutils-24.c
networking/dnsd.c
networking/httpd.c
networking/ifupdown.c
networking/inetd.c
networking/libiproute/ipaddress.c
networking/nameif.c
networking/netstat.c
procps/mpstat.c
procps/powertop.c
procps/pwdx.c
shell/hush.c
util-linux/acpid.c
util-linux/fdisk.c
util-linux/fdisk_osf.c
util-linux/fdisk_sgi.c
util-linux/findfs.c
util-linux/mdev.c
util-linux/mount.c
util-linux/rtcwake.c
util-linux/volume_id/get_devname.c

index 1a0058b63add5ee4ade6ae344f79482f531620b9..7861d1f6f146d1e39dd3653f9387e97d0ddcd49d 100644 (file)
@@ -37,7 +37,7 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
        }
        archive_handle->offset += 110;
 
-       if (strncmp(&cpio_header[0], "07070", 5) != 0
+       if (!is_prefixed_with(&cpio_header[0], "07070")
         || (cpio_header[5] != '1' && cpio_header[5] != '2')
        ) {
                bb_error_msg_and_die("unsupported cpio format, use newc or crc");
index 0c663fbd75bfef48f70b59b472063c883ce2ce92..2dbcdb50c1d806f447ed54a20ed0f3c186f68c7e 100644 (file)
@@ -105,7 +105,7 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
                value = end + 1;
 
 #if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
-               if (!global && strncmp(value, "path=", sizeof("path=") - 1) == 0) {
+               if (!global && is_prefixed_with(value, "path=")) {
                        value += sizeof("path=") - 1;
                        free(archive_handle->tar__longname);
                        archive_handle->tar__longname = xstrdup(value);
@@ -118,7 +118,7 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
                 * This is what Red Hat's patched version of tar uses.
                 */
 # define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux"
-               if (strncmp(value, SELINUX_CONTEXT_KEYWORD"=", sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1) == 0) {
+               if (is_prefixed_with(value, SELINUX_CONTEXT_KEYWORD"=")) {
                        value += sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1;
                        free(archive_handle->tar__sctx[global]);
                        archive_handle->tar__sctx[global] = xstrdup(value);
@@ -202,7 +202,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
 
        /* Check header has valid magic, "ustar" is for the proper tar,
         * five NULs are for the old tar format  */
-       if (strncmp(tar.magic, "ustar", 5) != 0
+       if (!is_prefixed_with(tar.magic, "ustar")
         && (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY
             || memcmp(tar.magic, "\0\0\0\0", 5) != 0)
        ) {
index 214d17e23ae17ccfa374c4f529e5167a34e1917d..0bc030349f5b3b930b73e6e14140cb06ea525070 100644 (file)
@@ -12,7 +12,7 @@ void FAST_FUNC unpack_ar_archive(archive_handle_t *ar_archive)
        char magic[7];
 
        xread(ar_archive->src_fd, magic, AR_MAGIC_LEN);
-       if (strncmp(magic, AR_MAGIC, AR_MAGIC_LEN) != 0) {
+       if (!is_prefixed_with(magic, AR_MAGIC)) {
                bb_error_msg_and_die("invalid ar magic");
        }
        ar_archive->offset += AR_MAGIC_LEN;
index 826c673bfdf9be2c14f765970e5927558feb590e..9994f4d94edf01f2815507a8b2ba1d7315d2171f 100644 (file)
@@ -15,7 +15,7 @@ const char* FAST_FUNC strip_unsafe_prefix(const char *str)
                        cp++;
                        continue;
                }
-               if (strncmp(cp, "/../"+1, 3) == 0) {
+               if (is_prefixed_with(cp, "/../"+1)) {
                        cp += 3;
                        continue;
                }
index 6dcf8133f9213f83d510067d6f03de78b5a5f062..f525ee5d11f52abe32d9b8b7596194b741a67ca5 100644 (file)
@@ -57,7 +57,7 @@ int loadkmap_main(int argc UNUSED_PARAM, char **argv)
 */
 
        xread(STDIN_FILENO, flags, 7);
-       if (strncmp(flags, BINARY_KEYMAP_MAGIC, 7))
+       if (!is_prefixed_with(flags, BINARY_KEYMAP_MAGIC))
                bb_error_msg_and_die("not a valid binary keymap");
 
        xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS);
index 767e0d4a29296f9c224a1013921f4387b82bdec1..7965775fefc8f4cccfa3355d05728600fc9bb4b9 100644 (file)
@@ -373,7 +373,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
                date_buf[0] = '\0';
        } else {
                /* Handle special conversions */
-               if (strncmp(fmt_dt2str, "%f", 2) == 0) {
+               if (is_prefixed_with(fmt_dt2str, "%f")) {
                        fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S";
                }
                /* Generate output string */
index b298fcb9535207e27f4b4d1c3c8e69c2435e3307..3f1227306d621e13446634bd3559edf5a9ab2612 100644 (file)
@@ -110,10 +110,10 @@ int uudecode_main(int argc UNUSED_PARAM, char **argv)
                FILE *dst_stream;
                int mode;
 
-               if (strncmp(line, "begin-base64 ", 13) == 0) {
+               if (is_prefixed_with(line, "begin-base64 ")) {
                        line_ptr = line + 13;
                        decode_fn_ptr = read_base64;
-               } else if (strncmp(line, "begin ", 6) == 0) {
+               } else if (is_prefixed_with(line, "begin ")) {
                        line_ptr = line + 6;
                        decode_fn_ptr = read_stduu;
                } else {
index d32f396e92a54af566d4790529f6de2ae808951c..d2d312e5c7793b41e44a5dddd9e5309d9f3c3248 100644 (file)
@@ -199,7 +199,7 @@ static char *base_device(const char *device)
        }
 
        /* Handle DAC 960 devices */
-       if (strncmp(cp, "rd/", 3) == 0) {
+       if (is_prefixed_with(cp, "rd/")) {
                cp += 3;
                if (cp[0] != 'c' || !isdigit(cp[1])
                 || cp[2] != 'd' || !isdigit(cp[3]))
@@ -224,9 +224,9 @@ static char *base_device(const char *device)
 #if ENABLE_FEATURE_DEVFS
        /* Now let's handle devfs (ugh) names */
        len = 0;
-       if (strncmp(cp, "ide/", 4) == 0)
+       if (is_prefixed_with(cp, "ide/"))
                len = 4;
-       if (strncmp(cp, "scsi/", 5) == 0)
+       if (is_prefixed_with(cp, "scsi/"))
                len = 5;
        if (len) {
                cp += len;
@@ -237,38 +237,38 @@ static char *base_device(const char *device)
                 * some number of digits at each level, abort.
                 */
                for (hier = devfs_hier; *hier; hier++) {
-                       len = strlen(*hier);
-                       if (strncmp(cp, *hier, len) != 0)
+                       cp = is_prefixed_with(cp, *hier);
+                       if (!cp)
                                goto errout;
-                       cp += len;
-                       while (*cp != '/' && *cp != 0) {
+                       while (*cp != '/' && *cp != '\0') {
                                if (!isdigit(*cp))
                                        goto errout;
                                cp++;
                        }
+//FIXME: what if *cp = '\0' now? cp++ moves past it!!!
                        cp++;
                }
-               cp[-1] = 0;
+               cp[-1] = '\0';
                return str;
        }
 
        /* Now handle devfs /dev/disc or /dev/disk names */
-       disk = 0;
-       if (strncmp(cp, "discs/", 6) == 0)
+       disk = NULL;
+       if (is_prefixed_with(cp, "discs/"))
                disk = "disc";
-       else if (strncmp(cp, "disks/", 6) == 0)
+       else if (is_prefixed_with(cp, "disks/"))
                disk = "disk";
        if (disk) {
                cp += 6;
-               if (strncmp(cp, disk, 4) != 0)
+               cp = is_prefixed_with(cp, disk);
+               if (!cp)
                        goto errout;
-               cp += 4;
-               while (*cp != '/' && *cp != 0) {
+               while (*cp != '/' && *cp != '\0') {
                        if (!isdigit(*cp))
                                goto errout;
                        cp++;
                }
-               *cp = 0;
+               *cp = '\0';
                return str;
        }
 #endif
@@ -593,8 +593,8 @@ static void fsck_device(struct fs_info *fs /*, int interactive */)
                                        type, "from fstab");
        } else if (fstype
         && (fstype[0] != 'n' || fstype[1] != 'o') /* != "no" */
-        && strncmp(fstype, "opts=", 5) != 0
-        && strncmp(fstype, "loop", 4) != 0
+        && !is_prefixed_with(fstype, "opts=")
+        && !is_prefixed_with(fstype, "loop")
         && !strchr(fstype, ',')
        ) {
                type = fstype;
@@ -627,8 +627,8 @@ static int device_already_active(char *device)
 #ifdef BASE_MD
        /* Don't check a soft raid disk with any other disk */
        if (instance_list
-        && (!strncmp(instance_list->device, BASE_MD, sizeof(BASE_MD)-1)
-            || !strncmp(device, BASE_MD, sizeof(BASE_MD)-1))
+        && (is_prefixed_with(instance_list->device, BASE_MD)
+            || is_prefixed_with(device, BASE_MD))
        ) {
                return 1;
        }
@@ -895,7 +895,7 @@ static void compile_fs_type(char *fs_type)
                if (strcmp(s, "loop") == 0)
                        /* loop is really short-hand for opts=loop */
                        goto loop_special_case;
-               if (strncmp(s, "opts=", 5) == 0) {
+               if (is_prefixed_with(s, "opts=")) {
                        s += 5;
  loop_special_case:
                        fs_type_flag[num] = negate ? FS_TYPE_FLAG_NEGOPT : FS_TYPE_FLAG_OPT;
index f8606754460fb9d2281ce9aac76673db4511c0ee..cb25e4140878f906cf64ac2cbe77d8344429650b 100644 (file)
@@ -414,7 +414,7 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
                }
 
                // Open a new file?
-               if (!strncmp("--- ", patchline, 4) || !strncmp("+++ ", patchline, 4)) {
+               if (is_prefixed_with(patchline, "--- ") || is_prefixed_with(patchline, "+++ ")) {
                        char *s, **name = reverse ? &newname : &oldname;
                        int i;
 
@@ -446,7 +446,7 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
 
                // Start a new hunk?  Usually @@ -oldline,oldlen +newline,newlen @@
                // but a missing ,value means the value is 1.
-               } else if (state == 1 && !strncmp("@@ -", patchline, 4)) {
+               } else if (state == 1 && is_prefixed_with(patchline, "@@ -")) {
                        int i;
                        char *s = patchline+4;
 
index be792d6b277b372b7c35b8c0a76892ceeeb0fd01..c97df604733248b0bb1fdbbdc14013f4564ea49f 100644 (file)
@@ -389,6 +389,7 @@ const char *bb_basename(const char *name) FAST_FUNC;
 /* NB: can violate const-ness (similarly to strchr) */
 char *last_char_is(const char *s, int c) FAST_FUNC;
 const char* endofname(const char *name) FAST_FUNC;
+char *is_prefixed_with(const char *string, const char *key) FAST_FUNC;
 
 int ndelay_on(int fd) FAST_FUNC;
 int ndelay_off(int fd) FAST_FUNC;
index 54300bd8726a9b4ac7205c80343ed4d94ef47660..8fd8fd5255c9a67496396fc7c451ac00c24393ed 100644 (file)
@@ -193,7 +193,7 @@ void lbb_prepare(const char *applet
        if (argv[1]
         && !argv[2]
         && strcmp(argv[1], "--help") == 0
-        && strncmp(applet, "busybox", 7) != 0
+        && !is_prefixed_with(applet, "busybox")
        ) {
                /* Special case. POSIX says "test --help"
                 * should be no different from e.g. "test --foo".  */
@@ -673,7 +673,7 @@ static int busybox_main(char **argv)
                return 0;
        }
 
-       if (strncmp(argv[1], "--list", 6) == 0) {
+       if (is_prefixed_with(argv[1], "--list")) {
                unsigned i = 0;
                const char *a = applet_names;
                dup2(1, 2);
@@ -778,7 +778,7 @@ void FAST_FUNC run_applet_and_exit(const char *name, char **argv)
        int applet = find_applet_by_name(name);
        if (applet >= 0)
                run_applet_no_and_exit(applet, argv);
-       if (strncmp(name, "busybox", 7) == 0)
+       if (is_prefixed_with(name, "busybox"))
                exit(busybox_main(argv));
 }
 
@@ -817,7 +817,7 @@ int main(int argc UNUSED_PARAM, char **argv)
 
 #if defined(SINGLE_APPLET_MAIN)
        /* Only one applet is selected in .config */
-       if (argv[1] && strncmp(argv[0], "busybox", 7) == 0) {
+       if (argv[1] && is_prefixed_with(argv[0], "busybox")) {
                /* "busybox <applet> <params>" should still work as expected */
                argv++;
        }
index 4b10cc138ab216556e12b93eecaa09a013e46f35..e24815a03f3ac2151430aaacc2841c6b65f6951e 100644 (file)
@@ -5,6 +5,24 @@
 
 #include "libbb.h"
 
+char* FAST_FUNC is_prefixed_with(const char *string, const char *key)
+{
+#if 0  /* Two passes over key - probably slower */
+       int len = strlen(key);
+       if (strncmp(string, key, len) == 0)
+               return string + len;
+       return NULL;
+#else  /* Open-coded */
+       while (*key != '\0') {
+               if (*key != *string)
+                       return NULL;
+               key++;
+               string++;
+       }
+       return (char*)string;
+#endif
+}
+
 /* returns the array index of the string */
 /* (index of first match is returned, or -1) */
 int FAST_FUNC index_in_str_array(const char *const string_array[], const char *key)
@@ -39,10 +57,9 @@ int FAST_FUNC index_in_strings(const char *strings, const char *key)
 int FAST_FUNC index_in_substr_array(const char *const string_array[], const char *key)
 {
        int i;
-       int len = strlen(key);
-       if (len) {
+       if (key[0]) {
                for (i = 0; string_array[i] != 0; i++) {
-                       if (strncmp(string_array[i], key, len) == 0) {
+                       if (is_prefixed_with(string_array[i], key)) {
                                return i;
                        }
                }
index 249b401b4b6e36c37473d05dec912bd69ce3e6f7..a83e07c0cda1db6fcbf086267af56dae3e69e295 100644 (file)
@@ -681,7 +681,7 @@ static NOINLINE unsigned complete_username(const char *ud)
        setpwent();
        while ((pw = getpwent()) != NULL) {
                /* Null usernames should result in all users as possible completions. */
-               if (/*!userlen || */ strncmp(ud, pw->pw_name, userlen) == 0) {
+               if (/* !ud[0] || */ is_prefixed_with(pw->pw_name, ud)) {
                        add_match(xasprintf("~%s/", pw->pw_name));
                }
        }
@@ -792,7 +792,7 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type)
                        if (!pfind[0] && DOT_OR_DOTDOT(name_found))
                                continue;
                        /* match? */
-                       if (strncmp(name_found, pfind, pf_len) != 0)
+                       if (!is_prefixed_with(name_found, pfind))
                                continue; /* no */
 
                        found = concat_path_file(paths[i], name_found);
@@ -1879,15 +1879,16 @@ static void parse_and_put_prompt(const char *prmt_ptr)
                                                cwd_buf = xrealloc_getcwd_or_warn(NULL);
                                                if (!cwd_buf)
                                                        cwd_buf = (char *)bb_msg_unknown;
-                                               else {
+                                               else if (home_pwd_buf[0]) {
+                                                       char *after_home_user;
+
                                                        /* /home/user[/something] -> ~[/something] */
-                                                       l = strlen(home_pwd_buf);
-                                                       if (l != 0
-                                                        && strncmp(home_pwd_buf, cwd_buf, l) == 0
-                                                        && (cwd_buf[l] == '/' || cwd_buf[l] == '\0')
+                                                       after_home_user = is_prefixed_with(cwd_buf, home_pwd_buf);
+                                                       if (after_home_user
+                                                        && (*after_home_user == '/' || *after_home_user == '\0')
                                                        ) {
                                                                cwd_buf[0] = '~';
-                                                               overlapping_strcpy(cwd_buf + 1, cwd_buf + l);
+                                                               overlapping_strcpy(cwd_buf + 1, after_home_user);
                                                        }
                                                }
                                        }
index 32c3d7f188a1c941ef56fdf76becb761c9026f59..b066b421177505ef5da819596dea30d8db994a6d 100644 (file)
@@ -17,7 +17,6 @@
 int FAST_FUNC match_fstype(const struct mntent *mt, const char *t_fstype)
 {
        int match = 1;
-       int len;
 
        if (!t_fstype)
                return match;
@@ -27,10 +26,10 @@ int FAST_FUNC match_fstype(const struct mntent *mt, const char *t_fstype)
                t_fstype += 2;
        }
 
-       len = strlen(mt->mnt_type);
        while (1) {
-               if (strncmp(mt->mnt_type, t_fstype, len) == 0
-                && (t_fstype[len] == '\0' || t_fstype[len] == ',')
+               char *after_mnt_type = is_prefixed_with(t_fstype, mt->mnt_type);
+               if (after_mnt_type
+                && (*after_mnt_type == '\0' || *after_mnt_type == ',')
                ) {
                        return match;
                }
index 5b68d343138566656441d00f7f508107ee601be4..948b91ee653284eea80ec87a045cb067c96edc3e 100644 (file)
@@ -205,11 +205,11 @@ int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total,
                // Rss:                 nnn kB
                // .....
 
-               char *tp = buf, *p;
+               char *tp, *p;
 
 #define SCAN(S, X) \
-               if (strncmp(tp, S, sizeof(S)-1) == 0) {              \
-                       tp = skip_whitespace(tp + sizeof(S)-1);      \
+               if ((tp = is_prefixed_with(buf, S)) != NULL) {       \
+                       tp = skip_whitespace(tp);                    \
                        total->X += currec.X = fast_strtoul_10(&tp); \
                        continue;                                    \
                }
@@ -247,7 +247,7 @@ int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total,
                        // skipping "rw-s FILEOFS M:m INODE "
                        tp = skip_whitespace(skip_fields(tp, 4));
                        // filter out /dev/something (something != zero)
-                       if (strncmp(tp, "/dev/", 5) != 0 || strcmp(tp, "/dev/zero\n") == 0) {
+                       if (!is_prefixed_with(tp, "/dev/") || strcmp(tp, "/dev/zero\n") == 0) {
                                if (currec.smap_mode[1] == 'w') {
                                        currec.mapped_rw = currec.smap_size;
                                        total->mapped_rw += currec.smap_size;
@@ -497,8 +497,8 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
                                while (fgets(buf, sizeof(buf), file)) {
                                        char *tp;
 #define SCAN_TWO(str, name, statement) \
-       if (strncmp(buf, str, sizeof(str)-1) == 0) { \
-               tp = skip_whitespace(buf + sizeof(str)-1); \
+       if ((tp = is_prefixed_with(buf, str)) != NULL) { \
+               tp = skip_whitespace(tp); \
                sscanf(tp, "%u", &sp->name); \
                statement; \
        }
index 6d06d57f9c212ab2991ace2252cab01da9fded62..c4117ba34f71902b74a4aee5e348969b8e330b38 100644 (file)
@@ -22,7 +22,7 @@ int FAST_FUNC rtc_adjtime_is_utc(void)
                char buffer[128];
 
                while (fgets(buffer, sizeof(buffer), f)) {
-                       if (strncmp(buffer, "UTC", 3) == 0) {
+                       if (is_prefixed_with(buffer, "UTC")) {
                                utc = 1;
                                break;
                        }
index 8c7b674c3ea8e9fe7ac0ec6f3a9dac54f34b3b09..b6cfbba4dc8c44c707779360e74ad9c743665e81 100644 (file)
@@ -33,7 +33,7 @@ char* FAST_FUNC skip_non_whitespace(const char *s)
 
 char* FAST_FUNC skip_dev_pfx(const char *tty_name)
 {
-       if (strncmp(tty_name, "/dev/", 5) == 0)
+       if (is_prefixed_with(tty_name, "/dev/"))
                tty_name += 5;
        return (char*)tty_name;
 }
index dc26ebd1d1a6a51afae912d9d10074e4120abcb8..a2004f480ca757a2faf3d3f1918ec3a05e9c3ddb 100644 (file)
@@ -84,7 +84,6 @@ int FAST_FUNC update_passwd(const char *filename,
        char *fnamesfx;
        char *sfx_char;
        char *name_colon;
-       unsigned user_len;
        int old_fd;
        int new_fd;
        int i;
@@ -108,7 +107,6 @@ int FAST_FUNC update_passwd(const char *filename,
        fnamesfx = xasprintf("%s+", filename);
        sfx_char = &fnamesfx[strlen(fnamesfx)-1];
        name_colon = xasprintf("%s:", name ? name : "");
-       user_len = strlen(name_colon);
 
        if (shadow)
                old_fp = fopen(filename, "r+");
@@ -179,7 +177,7 @@ int FAST_FUNC update_passwd(const char *filename,
                        while (list) {
                                list++;
  next_list_element:
-                               if (strncmp(list, member, member_len) == 0) {
+                               if (is_prefixed_with(list, member)) {
                                        char c;
                                        changed_lines++;
                                        c = list[member_len];
@@ -201,13 +199,14 @@ int FAST_FUNC update_passwd(const char *filename,
                        goto next;
                }
 
-               if (strncmp(name_colon, line, user_len) != 0) {
+               cp = is_prefixed_with(line, name_colon);
+               if (!cp) {
                        fprintf(new_fp, "%s\n", line);
                        goto next;
                }
 
                /* We have a match with "name:"... */
-               cp = line + user_len; /* move past name: */
+               /* cp points past "name:" */
 
 #if ENABLE_FEATURE_ADDUSER_TO_GROUP || ENABLE_FEATURE_DEL_USER_FROM_GROUP
                if (member) {
index 1c8bb2b7309a7ad0c77a1107e54c78da5d633eaf..2a96e03dc76d84a0bb8baec63ae28ed284749326 100644 (file)
@@ -171,7 +171,7 @@ IF_NOT_FEATURE_IPV6(sa_family_t af = AF_INET;)
        const char *cp;
        struct addrinfo hint;
 
-       if (ENABLE_FEATURE_UNIX_LOCAL && strncmp(host, "local:", 6) == 0) {
+       if (ENABLE_FEATURE_UNIX_LOCAL && is_prefixed_with(host, "local:")) {
                struct sockaddr_un *sun;
 
                r = xzalloc(LSA_LEN_SIZE + sizeof(struct sockaddr_un));
index 3659b9a6f151b34457872930290cd0dc6809c52c..eb327f8555692855d3b02f80c7110514a61fd7c7 100644 (file)
@@ -438,14 +438,14 @@ static void load_crontab(const char *fileName)
                        log5("user:%s entry:%s", fileName, parser->data);
 
                        /* check if line is setting MAILTO= */
-                       if (0 == strncmp(tokens[0], "MAILTO=", 7)) {
+                       if (is_prefixed_with(tokens[0], "MAILTO=")) {
 #if ENABLE_FEATURE_CROND_CALL_SENDMAIL
                                free(mailTo);
                                mailTo = (tokens[0][7]) ? xstrdup(&tokens[0][7]) : NULL;
 #endif /* otherwise just ignore such lines */
                                continue;
                        }
-                       if (0 == strncmp(tokens[0], "SHELL=", 6)) {
+                       if (is_prefixed_with(tokens[0], "SHELL=")) {
                                free(shell);
                                shell = xstrdup(&tokens[0][6]);
                                continue;
index a7bd360d223eedbee91fe38228b93e93280ed4b3..f94d6fa6b301c17119cfe0bcabfc6c227c24e880 100644 (file)
@@ -244,9 +244,9 @@ static void stack_machine(const char *argument)
 
        o = operators;
        do {
-               const size_t name_len = strlen(o->name);
-               if (strncmp(o->name, argument, name_len) == 0) {
-                       argument += name_len;
+               char *after_name = is_prefixed_with(argument, o->name);
+               if (after_name) {
+                       argument = after_name;
                        o->function();
                        goto next;
                }
index 96ffe073898dfa996bc41371ec5892dc100a6e94..5a6aec6bd6865260d2a65c721d80ef671cfa3bc6 100644 (file)
@@ -1405,7 +1405,6 @@ const char *get_old_name(const char *devname, unsigned int namelen,
        int indexx;
        const char *pty1;
        const char *pty2;
-       size_t len;
        /* 1 to 5  "scsi/" , 6 to 9 "ide/host", 10 sbp/, 11 vcc/, 12 pty/ */
        static const char *const fmt[] = {
                NULL ,
@@ -1425,12 +1424,11 @@ const char *get_old_name(const char *devname, unsigned int namelen,
        };
 
        for (trans = translate_table; trans->match != NULL; ++trans) {
-               len = strlen(trans->match);
-
-               if (strncmp(devname, trans->match, len) == 0) {
+               char *after_match = is_prefixed_with(devname, trans->match);
+               if (after_match) {
                        if (trans->format == NULL)
-                               return devname + len;
-                       sprintf(buffer, trans->format, devname + len);
+                               return after_match;
+                       sprintf(buffer, trans->format, after_match);
                        return buffer;
                }
        }
index 7b695b26f59539b70b94d8d5e525632a2cbd3155..77033c258cff354bf30ec331583676381affa477 100644 (file)
@@ -516,7 +516,7 @@ int fbsplash_main(int argc UNUSED_PARAM, char **argv)
        // handle a case when we have many buffered lines
        // already in the pipe
        while ((num_buf = xmalloc_fgetline(fp)) != NULL) {
-               if (strncmp(num_buf, "exit", 4) == 0) {
+               if (is_prefixed_with(num_buf, "exit")) {
                        DEBUG_MESSAGE("exit");
                        break;
                }
index 90d1e1e1480bede7ba94f2f2d84bca6b4f3e6ddf..03bb039742b1d3d59a4367058064f464a57ec3dc 100644 (file)
@@ -1198,7 +1198,7 @@ static void NORETURN list_i2c_busses_and_exit(void)
                                if (subde->d_name[0] == '.')
                                        continue;
 
-                               if (strncmp(subde->d_name, "i2c-", 4) == 0) {
+                               if (is_prefixed_with(subde->d_name, "i2c-")) {
                                        snprintf(path, NAME_MAX,
                                                 "%s/%s/device/%s/name",
                                                 i2cdev_path, de->d_name,
@@ -1229,7 +1229,7 @@ found:
                        if (rv != 1)
                                continue;
 
-                       if (strncmp(name, "ISA", 3) == 0)
+                       if (is_prefixed_with(name, "ISA"))
                                adt = ADT_ISA;
                        else
                                adt = i2cdetect_get_funcs(bus);
index 24f6e1c7820ed49b8280a4b01826162cff275654..a144c7e478c7877375888634fa406e19d3babe21 100644 (file)
@@ -87,11 +87,11 @@ int last_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
                        if (++n > 0)
                                ut.ut_type = n != 3 ? n : SHUTDOWN_TIME;
 #else
-                       if (strncmp(ut.ut_user, "shutdown", 8) == 0)
+                       if (is_prefixed_with(ut.ut_user, "shutdown"))
                                ut.ut_type = SHUTDOWN_TIME;
-                       else if (strncmp(ut.ut_user, "reboot", 6) == 0)
+                       else if (is_prefixed_with(ut.ut_user, "reboot"))
                                ut.ut_type = BOOT_TIME;
-                       else if (strncmp(ut.ut_user, "runlevel", 8) == 0)
+                       else if (is_prefixed_with(ut.ut_user, "runlevel"))
                                ut.ut_type = RUN_LVL;
 #endif
                } else {
index c39870e674b310d095e7c408f272b82d00cc61d7..58ed81955bd2318f8dba9d635b709c3b9dea1b10 100644 (file)
@@ -66,7 +66,7 @@ static int run_pipe(const char *pager, char *man_filename, int man, int level)
                        goto ordinary_manpage;
 
                line = xmalloc_open_zipped_read_close(man_filename, NULL);
-               if (!line || strncmp(line, ".so ", 4) != 0) {
+               if (!line || !is_prefixed_with(line, ".so ")) {
                        free(line);
                        goto ordinary_manpage;
                }
@@ -228,7 +228,7 @@ int man_main(int argc UNUSED_PARAM, char **argv)
                if (!token[1])
                        continue;
                if (strcmp("DEFINE", token[0]) == 0) {
-                       if (strncmp("pager", token[1], 5) == 0) {
+                       if (is_prefixed_with("pager", token[1])) {
                                pager = xstrdup(skip_whitespace(token[1]) + 5);
                        }
                } else
index 37a8482d92c8d43101f2d958d5c2413e34a88947..9713aef922783d9e53f2d89c310a9edffb7b84cf 100644 (file)
@@ -55,7 +55,7 @@ static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARA
                        NULL
        );
        for (ptr = image; ptr < image + len - 10; ptr++) {
-               if (strncmp(ptr, "depends=", 8) == 0) {
+               if (is_prefixed_with(ptr, "depends=")) {
                        char *u;
 
                        ptr += 8;
@@ -64,15 +64,15 @@ static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARA
                                        *u = '_';
                        ptr += string_to_llist(ptr, &info->dependencies, ",");
                } else if (ENABLE_FEATURE_MODUTILS_ALIAS
-                && strncmp(ptr, "alias=", 6) == 0
+                && is_prefixed_with(ptr, "alias=")
                ) {
                        llist_add_to(&info->aliases, xstrdup(ptr + 6));
                        ptr += strlen(ptr);
                } else if (ENABLE_FEATURE_MODUTILS_SYMBOLS
-                && strncmp(ptr, "__ksymtab_", 10) == 0
+                && is_prefixed_with(ptr, "__ksymtab_")
                ) {
                        ptr += 10;
-                       if (strncmp(ptr, "gpl", 3) == 0
+                       if (is_prefixed_with(ptr, "gpl")
                         || strcmp(ptr, "strings") == 0
                        ) {
                                continue;
index ee379304c198d4335418dcb816709d0431bf69f9..8e74b643896a6b573a244877bfcc3ea089bb7453 100644 (file)
@@ -62,7 +62,7 @@ static void modinfo(const char *path, const char *version,
                "firmware",
        };
        size_t len;
-       int j, length;
+       int j;
        char *ptr, *the_module;
        const char *field = env->field;
        int tags = env->tags;
@@ -94,16 +94,18 @@ static void modinfo(const char *path, const char *version,
                pattern = field;
                if ((1<<j) & OPT_TAGS)
                        pattern = shortcuts[j];
-               length = strlen(pattern);
                ptr = the_module;
                while (1) {
+                       char *after_pattern;
+
                        ptr = memchr(ptr, *pattern, len - (ptr - (char*)the_module));
                        if (ptr == NULL) /* no occurance left, done */
                                break;
-                       if (strncmp(ptr, pattern, length) == 0 && ptr[length] == '=') {
+                       after_pattern = is_prefixed_with(ptr, pattern);
+                       if (after_pattern && *after_pattern == '=') {
                                /* field prefixes are 0x80 or 0x00 */
-                               if ((ptr[-1] & 0x7F) == '\0') {
-                                       ptr += length + 1;
+                               if ((ptr[-1] & 0x7F) == 0x00) {
+                                       ptr = after_pattern + 1;
                                        display(ptr, pattern, (1<<j) != tags);
                                        ptr += strlen(ptr);
                                }
index ed177bb9bc67f37bad7f1e0d3b1fdf81f329fa97..9c941064b60f3534801cf378e3d79d554f0858d6 100644 (file)
@@ -116,21 +116,21 @@ static char* copy_stringbuf(void)
 
 static char* find_keyword(char *ptr, size_t len, const char *word)
 {
-       int wlen;
-
        if (!ptr) /* happens if xmalloc_open_zipped_read_close cannot read it */
                return NULL;
 
-       wlen = strlen(word);
-       len -= wlen - 1;
+       len -= strlen(word) - 1;
        while ((ssize_t)len > 0) {
                char *old = ptr;
+               char *after_word;
+
                /* search for the first char in word */
-               ptr = memchr(ptr, *word, len);
+               ptr = memchr(ptr, word[0], len);
                if (ptr == NULL) /* no occurance left, done */
                        break;
-               if (strncmp(ptr, word, wlen) == 0)
-                       return ptr + wlen; /* found, return ptr past it */
+               after_word = is_prefixed_with(ptr, word);
+               if (after_word)
+                       return after_word; /* found, return ptr past it */
                ++ptr;
                len -= (ptr - old);
        }
@@ -536,7 +536,7 @@ static module_info** find_alias(const char *alias)
 // TODO: open only once, invent config_rewind()
 static int already_loaded(const char *name)
 {
-       int ret, namelen;
+       int ret;
        char *line;
        FILE *fp;
 
@@ -545,15 +545,16 @@ static int already_loaded(const char *name)
        fp = fopen_for_read("/proc/modules");
        if (!fp)
                return 0;
-       namelen = strlen(name);
        while ((line = xmalloc_fgetline(fp)) != NULL) {
                char *live;
+               char *after_name;
 
                // Examples from kernel 3.14.6:
                //pcspkr 12718 0 - Live 0xffffffffa017e000
                //snd_timer 28690 2 snd_seq,snd_pcm, Live 0xffffffffa025e000
                //i915 801405 2 - Live 0xffffffffa0096000
-               if (strncmp(line, name, namelen) != 0 || line[namelen] != ' ') {
+               after_name = is_prefixed_with(line, name);
+               if (!after_name || *after_name != ' ') {
                        free(line);
                        continue;
                }
index 0e8aa9e85da894e2d98c7ac6011e5b4ca48012dd..996de4074cd0c885f058111d41281e170892052a 100644 (file)
@@ -260,7 +260,7 @@ static void add_probe(const char *name)
        llist_add_to_end(&G.probes, m);
        G.num_unresolved_deps++;
        if (ENABLE_FEATURE_MODUTILS_SYMBOLS
-        && strncmp(m->modname, "symbol:", 7) == 0
+        && is_prefixed_with(m->modname, "symbol:")
        ) {
                G.need_symbols = 1;
        }
@@ -353,22 +353,18 @@ static char *parse_and_add_kcmdline_module_options(char *options, const char *mo
        char *kcmdline_buf;
        char *kcmdline;
        char *kptr;
-       int len;
 
        kcmdline_buf = xmalloc_open_read_close("/proc/cmdline", NULL);
        if (!kcmdline_buf)
                return options;
 
        kcmdline = kcmdline_buf;
-       len = strlen(modulename);
        while ((kptr = strsep(&kcmdline, "\n\t ")) != NULL) {
-               if (strncmp(modulename, kptr, len) != 0)
-                       continue;
-               kptr += len;
-               if (*kptr != '.')
+               char *after_modulename = is_prefixed_with(kptr, modulename);
+               if (!after_modulename || *after_modulename != '.')
                        continue;
                /* It is "modulename.xxxx" */
-               kptr++;
+               kptr = after_modulename + 1;
                if (strchr(kptr, '=') != NULL) {
                        /* It is "modulename.opt=[val]" */
                        options = gather_options_str(options, kptr);
index 12cb75c54c845915e398bfd0f0d8ddc04af6ec9c..fe46fc3fdfa5a4ffdbf589a490a0d9c0cc3fc5be 100644 (file)
@@ -2255,7 +2255,7 @@ static int add_symbols_from(struct obj_file *f,
                 * symbols so they cannot fudge it by adding the prefix on
                 * their references.
                 */
-               if (strncmp((char *)s->name, "GPLONLY_", 8) == 0) {
+               if (is_prefixed_with((char *)s->name, "GPLONLY_")) {
 #if ENABLE_FEATURE_CHECK_TAINTED_MODULE
                        if (gpl)
                                s->name += 8;
index fe98400f7d6047fc38c40e02f317afa8e51b4c2d..923ad6bc6ba1823a1f754ddfc7a0a02455c294d2 100644 (file)
@@ -194,7 +194,7 @@ static char *table_lookup(struct dns_entry *d,
                if ((len != 1 || d->name[1] != '*')
                /* we assume (do not check) that query_string
                 * ends in ".in-addr.arpa" */
-                && strncmp(d->rip, query_string, strlen(d->rip)) == 0
+                && is_prefixed_with(query_string, d->rip)
                ) {
 #if DEBUG
                        fprintf(stderr, "Found name:%s\n", d->name);
index 9cf0804019ab57064d6fca23451c6fd81f210629..7a9065fcc0536227e05961afaa1dce54b049b559 100644 (file)
@@ -697,7 +697,7 @@ static void parse_conf(const char *path, int flag)
                                goto config_error;
                        }
                        *host_port++ = '\0';
-                       if (strncmp(host_port, "http://", 7) == 0)
+                       if (is_prefixed_with(host_port, "http://"))
                                host_port += 7;
                        if (*host_port == '\0') {
                                goto config_error;
@@ -1894,7 +1894,7 @@ static Htaccess_Proxy *find_proxy_entry(const char *url)
 {
        Htaccess_Proxy *p;
        for (p = proxy; p; p = p->next) {
-               if (strncmp(url, p->url_from, strlen(p->url_from)) == 0)
+               if (is_prefixed_with(url, p->url_from))
                        return p;
        }
        return NULL;
@@ -2183,7 +2183,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
                        if (STRNCASECMP(iobuf, "Range:") == 0) {
                                /* We know only bytes=NNN-[MMM] */
                                char *s = skip_whitespace(iobuf + sizeof("Range:")-1);
-                               if (strncmp(s, "bytes=", 6) == 0) {
+                               if (is_prefixed_with(s, "bytes=") == 0) {
                                        s += sizeof("bytes=")-1;
                                        range_start = BB_STRTOOFF(s, &s, 10);
                                        if (s[0] != '-' || range_start < 0) {
@@ -2269,7 +2269,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
        tptr = urlcopy + 1;      /* skip first '/' */
 
 #if ENABLE_FEATURE_HTTPD_CGI
-       if (strncmp(tptr, "cgi-bin/", 8) == 0) {
+       if (is_prefixed_with(tptr, "cgi-bin/")) {
                if (tptr[8] == '\0') {
                        /* protect listing "cgi-bin/" */
                        send_headers_and_exit(HTTP_FORBIDDEN);
index c35d97a1aae5f82b93b0692b1f9af22f2cd09fcb..daabeec0cce5c403f0fb94b9266ae04ad82911b3 100644 (file)
@@ -289,7 +289,7 @@ static char *parse(const char *command, struct interface_defn_t *ifd)
                                        /* "hwaddress <class> <address>":
                                         * unlike ifconfig, ip doesnt want <class>
                                         * (usually "ether" keyword). Skip it. */
-                                       if (strncmp(command, "hwaddress", 9) == 0) {
+                                       if (is_prefixed_with(command, "hwaddress")) {
                                                varvalue = skip_whitespace(skip_non_whitespace(varvalue));
                                        }
 # endif
@@ -298,7 +298,7 @@ static char *parse(const char *command, struct interface_defn_t *ifd)
 # if ENABLE_FEATURE_IFUPDOWN_IP
                                        /* Sigh...  Add a special case for 'ip' to convert from
                                         * dotted quad to bit count style netmasks.  */
-                                       if (strncmp(command, "bnmask", 6) == 0) {
+                                       if (is_prefixed_with(command, "bnmask")) {
                                                unsigned res;
                                                varvalue = get_var("netmask", 7, ifd);
                                                if (varvalue) {
@@ -1159,12 +1159,12 @@ static char *run_mapping(char *physical, struct mapping_defn_t *map)
 
 static llist_t *find_iface_state(llist_t *state_list, const char *iface)
 {
-       unsigned iface_len = strlen(iface);
        llist_t *search = state_list;
 
        while (search) {
-               if ((strncmp(search->data, iface, iface_len) == 0)
-                && (search->data[iface_len] == '=')
+               char *after_iface = is_prefixed_with(search->data, iface);
+               if (after_iface
+                && *after_iface == '='
                ) {
                        return search;
                }
index 8148925ce30998f3db50e89c17b326103e68755f..dce5a088593976e0a53e2f7adcacbd93a2e44a14 100644 (file)
@@ -727,7 +727,7 @@ static NOINLINE servtab_t *parse_one_line(void)
                        goto parse_err;
 #endif
                }
-               if (strncmp(arg, "rpc/", 4) == 0) {
+               if (is_prefixed_with(arg, "rpc/")) {
 #if ENABLE_FEATURE_INETD_RPC
                        unsigned n;
                        arg += 4;
index aa4779ad1225d4f8daa0f1a3de0157b862adc8a5..4072d06262877997bb8e5734bb4a35aa072392ef 100644 (file)
@@ -701,7 +701,7 @@ static int ipaddr_modify(int cmd, char **argv)
                /* There was no "dev IFACE", but we need that */
                bb_error_msg_and_die("need \"dev IFACE\"");
        }
-       if (l && strncmp(d, l, strlen(d)) != 0) {
+       if (l && !is_prefixed_with(l, d)) {
                bb_error_msg_and_die("\"dev\" (%s) must match \"label\" (%s)", d, l);
        }
 
index 9a8846dc0a534e583fbf50c43286201c343707d0..9b18a6d1645db2e9622f9b0805adffde886398d0 100644 (file)
@@ -161,19 +161,19 @@ static void nameif_parse_selector(ethtable_t *ch, char *selector)
                if (*next)
                        *next++ = '\0';
                /* Check for selectors, mac= is assumed */
-               if (strncmp(selector, "bus=", 4) == 0) {
+               if (is_prefixed_with(selector, "bus=")) {
                        ch->bus_info = xstrdup(selector + 4);
                        found_selector++;
-               } else if (strncmp(selector, "driver=", 7) == 0) {
+               } else if (is_prefixed_with(selector, "driver=")) {
                        ch->driver = xstrdup(selector + 7);
                        found_selector++;
-               } else if (strncmp(selector, "phyaddr=", 8) == 0) {
+               } else if (is_prefixed_with(selector, "phyaddr=")) {
                        ch->phy_address = xatoi_positive(selector + 8);
                        found_selector++;
                } else {
 #endif
                        lmac = xmalloc(ETH_ALEN);
-                       ch->mac = ether_aton_r(selector + (strncmp(selector, "mac=", 4) != 0 ? 0 : 4), lmac);
+                       ch->mac = ether_aton_r(selector + (is_prefixed_with(selector, "mac=") ? 4 : 0), lmac);
                        if (ch->mac == NULL)
                                bb_error_msg_and_die("can't parse %s", selector);
 #if  ENABLE_FEATURE_NAMEIF_EXTENDED
index f80b845bc98612b4e9749c0be5eccc89e494d491..02f4cc7cc9ae4ccc1fac99aa1bbd34f38a23d0e6 100644 (file)
@@ -228,12 +228,12 @@ static long extract_socket_inode(const char *lname)
 {
        long inode = -1;
 
-       if (strncmp(lname, "socket:[", sizeof("socket:[")-1) == 0) {
+       if (is_prefixed_with(lname, "socket:[")) {
                /* "socket:[12345]", extract the "12345" as inode */
                inode = bb_strtoul(lname + sizeof("socket:[")-1, (char**)&lname, 0);
                if (*lname != ']')
                        inode = -1;
-       } else if (strncmp(lname, "[0000]:", sizeof("[0000]:")-1) == 0) {
+       } else if (is_prefixed_with(lname, "[0000]:")) {
                /* "[0000]:12345", extract the "12345" as inode */
                inode = bb_strtoul(lname + sizeof("[0000]:")-1, NULL, 0);
                if (errno) /* not NUL terminated? */
index af3263d67e67dfd446acf60296e418f6e702efa8..6028903fa5e4bb42db90588eff05e80cedb3e989 100644 (file)
@@ -526,7 +526,7 @@ static void get_irqs_from_stat(struct stats_irq *irq)
 
        while (fgets(buf, sizeof(buf), fp)) {
                //bb_error_msg("/proc/stat:'%s'", buf);
-               if (strncmp(buf, "intr ", 5) == 0) {
+               if (is_prefixed_with(buf, "intr ")) {
                        /* Read total number of IRQs since system boot */
                        sscanf(buf + 5, "%"FMT_DATA"u", &irq->irq_nr);
                }
index ddda5bd9362e9529d83a0b4c329ce760fa73c0ae..18affacdd790041a5da0df75014d991f6e2f8593 100644 (file)
@@ -458,9 +458,9 @@ static NOINLINE int process_timer_stats(void)
                        //      func = "Load balancing tick";
                        //}
 
-                       if (strncmp(func, "tick_nohz_", 10) == 0)
+                       if (is_prefixed_with(func, "tick_nohz_"))
                                continue;
-                       if (strncmp(func, "tick_setup_sched_timer", 20) == 0)
+                       if (is_prefixed_with(func, "tick_setup_sched_timer"))
                                continue;
                        //if (strcmp(process, "powertop") == 0)
                        //      continue;
index 22b892275a61ccadfd268c1159cb75fcb1082f56..4e34149ed319fd43a80af683bf9a666a01f199aa 100644 (file)
@@ -41,7 +41,7 @@ int pwdx_main(int argc UNUSED_PARAM, char **argv)
                // Allowed on the command line:
                // /proc/NUM
                // NUM
-               if (strncmp(arg, "/proc/", 6) == 0)
+               if (is_prefixed_with(arg, "/proc/"))
                        arg += 6;
 
                pid = bb_strtou(arg, NULL, 10);
index 92d79018019fca42014e981d379307c143f5a639..f2c0a70f20fed284c9f847513c68f0a7b6530616 100644 (file)
@@ -5884,7 +5884,7 @@ static FILE *generate_stream_from_string(const char *s, pid_t *pid_p)
                 * Our solution: ONLY bare $(trap) or `trap` is special.
                 */
                s = skip_whitespace(s);
-               if (strncmp(s, "trap", 4) == 0
+               if (is_prefixed_with(s, "trap")
                 && skip_whitespace(s + 4)[0] == '\0'
                ) {
                        static const char *const argv[] = { NULL, NULL };
index fc8151f6aa46634c99e067b8358f40cd9ad3db7e..0f2cb6bdc5f990953b1d31391ff67dd34fc13868 100644 (file)
@@ -151,7 +151,7 @@ static const char *find_action(struct input_event *ev, const char *buf)
                }
 
                if (buf) {
-                       if (strncmp(buf, evt_tab[i].desc, strlen(buf)) == 0) {
+                       if (is_prefixed_with(evt_tab[i].desc, buf)) {
                                action = evt_tab[i].desc;
                                break;
                        }
index 39eb27b470dd0df900b97493eb20b15b2822cadb..7fe70fb72a4b1aa36bc677cb0a429534d85891c3 100644 (file)
@@ -2781,14 +2781,14 @@ is_ide_cdrom_or_tape(const char *device)
           the process hangs on the attempt to read a music CD.
           So try to be careful. This only works since 2.1.73. */
 
-       if (strncmp("/dev/hd", device, 7))
+       if (!is_prefixed_with(device, "/dev/hd"))
                return 0;
 
        snprintf(buf, sizeof(buf), "/proc/ide/%s/media", device+5);
        procf = fopen_for_read(buf);
        if (procf != NULL && fgets(buf, sizeof(buf), procf))
-               is_ide = (!strncmp(buf, "cdrom", 5) ||
-                         !strncmp(buf, "tape", 4));
+               is_ide = (is_prefixed_with(buf, "cdrom") ||
+                         is_prefixed_with(buf, "tape"));
        else
                /* Now when this proc file does not exist, skip the
                   device when it is read-only. */
index ff16389bd5a7aa834f3f1f86a151c92beed505af..af04cfcc8fb2146fab28dda46bed8f3199078cbd 100644 (file)
@@ -854,7 +854,7 @@ xbsd_initlabel(struct partition *p)
 
        d->d_magic = BSD_DISKMAGIC;
 
-       if (strncmp(disk_device, "/dev/sd", 7) == 0)
+       if (is_prefixed_with(disk_device, "/dev/sd"))
                d->d_type = BSD_DTYPE_SCSI;
        else
                d->d_type = BSD_DTYPE_ST506;
index 785fc661b274f7ac773149478063280973864bce..23ebc56ef456e5a9c4c39ccaf4d5c3e6085adf34 100644 (file)
@@ -440,7 +440,7 @@ sgi_write_table(void)
                (unsigned int*)sgilabel, sizeof(*sgilabel)) == 0);
 
        write_sector(0, sgilabel);
-       if (!strncmp((char*)sgilabel->directory[0].vol_file_name, "sgilabel", 8)) {
+       if (is_prefixed_with((char*)sgilabel->directory[0].vol_file_name, "sgilabel")) {
                /*
                 * keep this habit of first writing the "sgilabel".
                 * I never tested whether it works without (AN 981002).
index 49e8979acf0b85b2120fa174f672b4baa6e4bdab..07734f3592a7665cfa7214191806cf02bec3547f 100644 (file)
@@ -27,7 +27,7 @@ int findfs_main(int argc UNUSED_PARAM, char **argv)
        if (!dev)
                bb_show_usage();
 
-       if (strncmp(dev, "/dev/", 5) == 0) {
+       if (is_prefixed_with(dev, "/dev/")) {
                /* Just pass any /dev/xxx name right through.
                 * This might aid in some scripts being able
                 * to call this unconditionally */
index b2d56575feafa10ef0285a2dd4171c7412c22ccb..ccc00d3656ac088b4a8412fb45b3a201f034a3ab 100644 (file)
@@ -610,7 +610,7 @@ static void make_device(char *device_name, char *path, int operation)
         * We use strstr("/block/") to forestall future surprises.
         */
        type = S_IFCHR;
-       if (strstr(path, "/block/") || (G.subsystem && strncmp(G.subsystem, "block", 5) == 0))
+       if (strstr(path, "/block/") || (G.subsystem && is_prefixed_with(G.subsystem, "block")))
                type = S_IFBLK;
 
 #if ENABLE_FEATURE_MDEV_CONF
index fbc89c862f3f7a6fe6778f6a95c0cf424007a3d6..cb40c802db1f48984cec05b5d5b7d7aadb5ea876 100644 (file)
@@ -641,7 +641,7 @@ static llist_t *get_block_backed_filesystems(void)
                if (!f) continue;
 
                while ((buf = xmalloc_fgetline(f)) != NULL) {
-                       if (strncmp(buf, "nodev", 5) == 0 && isspace(buf[5]))
+                       if (is_prefixed_with(buf, "nodev") && isspace(buf[5]))
                                goto next;
                        fs = skip_whitespace(buf);
                        if (*fs == '#' || *fs == '*' || !*fs)
@@ -1364,9 +1364,9 @@ static NOINLINE int nfsmount(struct mntent *mp, unsigned long vfsflags, char *fi
                                                strcspn(opteq, " \t\n\r,"));
                                continue;
                        case 18: // "proto"
-                               if (!strncmp(opteq, "tcp", 3))
+                               if (is_prefixed_with(opteq, "tcp"))
                                        tcp = 1;
-                               else if (!strncmp(opteq, "udp", 3))
+                               else if (is_prefixed_with(opteq, "udp"))
                                        tcp = 0;
                                else
                                        bb_error_msg("warning: unrecognized proto= option");
@@ -1459,7 +1459,7 @@ static NOINLINE int nfsmount(struct mntent *mp, unsigned long vfsflags, char *fi
                                "rdirplus\0"
                                "acl\0";
                        int val = 1;
-                       if (!strncmp(opt, "no", 2)) {
+                       if (is_prefixed_with(opt, "no")) {
                                val = 0;
                                opt += 2;
                        }
@@ -1979,7 +1979,7 @@ static int singlemount(struct mntent *mp, int ignore_busy)
        }
 
        // Might this be an NFS filesystem?
-       if ((!mp->mnt_type || strncmp(mp->mnt_type, "nfs", 3) == 0)
+       if ((!mp->mnt_type || is_prefixed_with(mp->mnt_type, "nfs"))
         && strchr(mp->mnt_fsname, ':') != NULL
        ) {
                if (!mp->mnt_type)
index 53d9384dbfe224b6e2e31cc7d7bc43cfe5f97dc5..8aee0cfcbd567dc8c0682da07e587387ee685f09 100644 (file)
@@ -66,7 +66,7 @@ static NOINLINE bool may_wakeup(const char *rtcname)
                return false;
 
        /* wakeup events could be disabled or not supported */
-       return strncmp(buf, "enabled\n", 8) == 0;
+       return is_prefixed_with(buf, "enabled\n") != NULL;
 }
 
 static NOINLINE void setup_alarm(int fd, time_t *wakeup, time_t rtc_time)
index 0c6bdfddf7754bc9bb0c77732c12fdbf469f565e..53bdbdf09f346c7820e45110366235bd1b70f3de 100644 (file)
@@ -302,9 +302,9 @@ int resolve_mount_spec(char **fsname)
 {
        char *tmp = *fsname;
 
-       if (strncmp(*fsname, "UUID=", 5) == 0)
+       if (is_prefixed_with(*fsname, "UUID="))
                tmp = get_devname_from_uuid(*fsname + 5);
-       else if (strncmp(*fsname, "LABEL=", 6) == 0)
+       else if (is_prefixed_with(*fsname, "LABEL=") == 0)
                tmp = get_devname_from_label(*fsname + 6);
 
        if (tmp == *fsname)