aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2015-03-12 17:48:34 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2015-03-12 17:48:34 +0100
commit8dff01d06a7ebd7330e3a1dd1ba47b3c74ee7dfb (patch)
tree41c9dfbd45676c9e8737a7d8aa4361bbdfb40868
parent936c8809caea5705e26e5d7e06ea3895c28fffd8 (diff)
downloadbusybox-w32-8dff01d06a7ebd7330e3a1dd1ba47b3c74ee7dfb.tar.gz
busybox-w32-8dff01d06a7ebd7330e3a1dd1ba47b3c74ee7dfb.tar.bz2
busybox-w32-8dff01d06a7ebd7330e3a1dd1ba47b3c74ee7dfb.zip
libbb: introduce and use is_prefixed_with()
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>
-rw-r--r--archival/libarchive/get_header_cpio.c2
-rw-r--r--archival/libarchive/get_header_tar.c6
-rw-r--r--archival/libarchive/unpack_ar_archive.c2
-rw-r--r--archival/libarchive/unsafe_prefix.c2
-rw-r--r--console-tools/loadkmap.c2
-rw-r--r--coreutils/date.c2
-rw-r--r--coreutils/uudecode.c4
-rw-r--r--e2fsprogs/fsck.c40
-rw-r--r--editors/patch.c4
-rw-r--r--include/libbb.h1
-rw-r--r--libbb/appletlib.c8
-rw-r--r--libbb/compare_string_array.c23
-rw-r--r--libbb/lineedit.c17
-rw-r--r--libbb/match_fstype.c7
-rw-r--r--libbb/procps.c12
-rw-r--r--libbb/rtc.c2
-rw-r--r--libbb/skip_whitespace.c2
-rw-r--r--libbb/update_passwd.c9
-rw-r--r--libbb/xconnect.c2
-rw-r--r--miscutils/crond.c4
-rw-r--r--miscutils/dc.c6
-rw-r--r--miscutils/devfsd.c10
-rw-r--r--miscutils/fbsplash.c2
-rw-r--r--miscutils/i2c_tools.c4
-rw-r--r--miscutils/last.c6
-rw-r--r--miscutils/man.c4
-rw-r--r--modutils/depmod.c8
-rw-r--r--modutils/modinfo.c12
-rw-r--r--modutils/modprobe-small.c21
-rw-r--r--modutils/modprobe.c12
-rw-r--r--modutils/modutils-24.c2
-rw-r--r--networking/dnsd.c2
-rw-r--r--networking/httpd.c8
-rw-r--r--networking/ifupdown.c10
-rw-r--r--networking/inetd.c2
-rw-r--r--networking/libiproute/ipaddress.c2
-rw-r--r--networking/nameif.c8
-rw-r--r--networking/netstat.c4
-rw-r--r--procps/mpstat.c2
-rw-r--r--procps/powertop.c4
-rw-r--r--procps/pwdx.c2
-rw-r--r--shell/hush.c2
-rw-r--r--util-linux/acpid.c2
-rw-r--r--util-linux/fdisk.c6
-rw-r--r--util-linux/fdisk_osf.c2
-rw-r--r--util-linux/fdisk_sgi.c2
-rw-r--r--util-linux/findfs.c2
-rw-r--r--util-linux/mdev.c2
-rw-r--r--util-linux/mount.c10
-rw-r--r--util-linux/rtcwake.c2
-rw-r--r--util-linux/volume_id/get_devname.c4
51 files changed, 165 insertions, 151 deletions
diff --git a/archival/libarchive/get_header_cpio.c b/archival/libarchive/get_header_cpio.c
index 1a0058b63..7861d1f6f 100644
--- a/archival/libarchive/get_header_cpio.c
+++ b/archival/libarchive/get_header_cpio.c
@@ -37,7 +37,7 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
37 } 37 }
38 archive_handle->offset += 110; 38 archive_handle->offset += 110;
39 39
40 if (strncmp(&cpio_header[0], "07070", 5) != 0 40 if (!is_prefixed_with(&cpio_header[0], "07070")
41 || (cpio_header[5] != '1' && cpio_header[5] != '2') 41 || (cpio_header[5] != '1' && cpio_header[5] != '2')
42 ) { 42 ) {
43 bb_error_msg_and_die("unsupported cpio format, use newc or crc"); 43 bb_error_msg_and_die("unsupported cpio format, use newc or crc");
diff --git a/archival/libarchive/get_header_tar.c b/archival/libarchive/get_header_tar.c
index 0c663fbd7..2dbcdb50c 100644
--- a/archival/libarchive/get_header_tar.c
+++ b/archival/libarchive/get_header_tar.c
@@ -105,7 +105,7 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
105 value = end + 1; 105 value = end + 1;
106 106
107#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS 107#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
108 if (!global && strncmp(value, "path=", sizeof("path=") - 1) == 0) { 108 if (!global && is_prefixed_with(value, "path=")) {
109 value += sizeof("path=") - 1; 109 value += sizeof("path=") - 1;
110 free(archive_handle->tar__longname); 110 free(archive_handle->tar__longname);
111 archive_handle->tar__longname = xstrdup(value); 111 archive_handle->tar__longname = xstrdup(value);
@@ -118,7 +118,7 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
118 * This is what Red Hat's patched version of tar uses. 118 * This is what Red Hat's patched version of tar uses.
119 */ 119 */
120# define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux" 120# define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux"
121 if (strncmp(value, SELINUX_CONTEXT_KEYWORD"=", sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1) == 0) { 121 if (is_prefixed_with(value, SELINUX_CONTEXT_KEYWORD"=")) {
122 value += sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1; 122 value += sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1;
123 free(archive_handle->tar__sctx[global]); 123 free(archive_handle->tar__sctx[global]);
124 archive_handle->tar__sctx[global] = xstrdup(value); 124 archive_handle->tar__sctx[global] = xstrdup(value);
@@ -202,7 +202,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
202 202
203 /* Check header has valid magic, "ustar" is for the proper tar, 203 /* Check header has valid magic, "ustar" is for the proper tar,
204 * five NULs are for the old tar format */ 204 * five NULs are for the old tar format */
205 if (strncmp(tar.magic, "ustar", 5) != 0 205 if (!is_prefixed_with(tar.magic, "ustar")
206 && (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY 206 && (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY
207 || memcmp(tar.magic, "\0\0\0\0", 5) != 0) 207 || memcmp(tar.magic, "\0\0\0\0", 5) != 0)
208 ) { 208 ) {
diff --git a/archival/libarchive/unpack_ar_archive.c b/archival/libarchive/unpack_ar_archive.c
index 214d17e23..0bc030349 100644
--- a/archival/libarchive/unpack_ar_archive.c
+++ b/archival/libarchive/unpack_ar_archive.c
@@ -12,7 +12,7 @@ void FAST_FUNC unpack_ar_archive(archive_handle_t *ar_archive)
12 char magic[7]; 12 char magic[7];
13 13
14 xread(ar_archive->src_fd, magic, AR_MAGIC_LEN); 14 xread(ar_archive->src_fd, magic, AR_MAGIC_LEN);
15 if (strncmp(magic, AR_MAGIC, AR_MAGIC_LEN) != 0) { 15 if (!is_prefixed_with(magic, AR_MAGIC)) {
16 bb_error_msg_and_die("invalid ar magic"); 16 bb_error_msg_and_die("invalid ar magic");
17 } 17 }
18 ar_archive->offset += AR_MAGIC_LEN; 18 ar_archive->offset += AR_MAGIC_LEN;
diff --git a/archival/libarchive/unsafe_prefix.c b/archival/libarchive/unsafe_prefix.c
index 826c673bf..9994f4d94 100644
--- a/archival/libarchive/unsafe_prefix.c
+++ b/archival/libarchive/unsafe_prefix.c
@@ -15,7 +15,7 @@ const char* FAST_FUNC strip_unsafe_prefix(const char *str)
15 cp++; 15 cp++;
16 continue; 16 continue;
17 } 17 }
18 if (strncmp(cp, "/../"+1, 3) == 0) { 18 if (is_prefixed_with(cp, "/../"+1)) {
19 cp += 3; 19 cp += 3;
20 continue; 20 continue;
21 } 21 }
diff --git a/console-tools/loadkmap.c b/console-tools/loadkmap.c
index 6dcf8133f..f525ee5d1 100644
--- a/console-tools/loadkmap.c
+++ b/console-tools/loadkmap.c
@@ -57,7 +57,7 @@ int loadkmap_main(int argc UNUSED_PARAM, char **argv)
57*/ 57*/
58 58
59 xread(STDIN_FILENO, flags, 7); 59 xread(STDIN_FILENO, flags, 7);
60 if (strncmp(flags, BINARY_KEYMAP_MAGIC, 7)) 60 if (!is_prefixed_with(flags, BINARY_KEYMAP_MAGIC))
61 bb_error_msg_and_die("not a valid binary keymap"); 61 bb_error_msg_and_die("not a valid binary keymap");
62 62
63 xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS); 63 xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS);
diff --git a/coreutils/date.c b/coreutils/date.c
index 767e0d4a2..7965775fe 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -373,7 +373,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
373 date_buf[0] = '\0'; 373 date_buf[0] = '\0';
374 } else { 374 } else {
375 /* Handle special conversions */ 375 /* Handle special conversions */
376 if (strncmp(fmt_dt2str, "%f", 2) == 0) { 376 if (is_prefixed_with(fmt_dt2str, "%f")) {
377 fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S"; 377 fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S";
378 } 378 }
379 /* Generate output string */ 379 /* Generate output string */
diff --git a/coreutils/uudecode.c b/coreutils/uudecode.c
index b298fcb95..3f1227306 100644
--- a/coreutils/uudecode.c
+++ b/coreutils/uudecode.c
@@ -110,10 +110,10 @@ int uudecode_main(int argc UNUSED_PARAM, char **argv)
110 FILE *dst_stream; 110 FILE *dst_stream;
111 int mode; 111 int mode;
112 112
113 if (strncmp(line, "begin-base64 ", 13) == 0) { 113 if (is_prefixed_with(line, "begin-base64 ")) {
114 line_ptr = line + 13; 114 line_ptr = line + 13;
115 decode_fn_ptr = read_base64; 115 decode_fn_ptr = read_base64;
116 } else if (strncmp(line, "begin ", 6) == 0) { 116 } else if (is_prefixed_with(line, "begin ")) {
117 line_ptr = line + 6; 117 line_ptr = line + 6;
118 decode_fn_ptr = read_stduu; 118 decode_fn_ptr = read_stduu;
119 } else { 119 } else {
diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c
index d32f396e9..d2d312e5c 100644
--- a/e2fsprogs/fsck.c
+++ b/e2fsprogs/fsck.c
@@ -199,7 +199,7 @@ static char *base_device(const char *device)
199 } 199 }
200 200
201 /* Handle DAC 960 devices */ 201 /* Handle DAC 960 devices */
202 if (strncmp(cp, "rd/", 3) == 0) { 202 if (is_prefixed_with(cp, "rd/")) {
203 cp += 3; 203 cp += 3;
204 if (cp[0] != 'c' || !isdigit(cp[1]) 204 if (cp[0] != 'c' || !isdigit(cp[1])
205 || cp[2] != 'd' || !isdigit(cp[3])) 205 || cp[2] != 'd' || !isdigit(cp[3]))
@@ -224,9 +224,9 @@ static char *base_device(const char *device)
224#if ENABLE_FEATURE_DEVFS 224#if ENABLE_FEATURE_DEVFS
225 /* Now let's handle devfs (ugh) names */ 225 /* Now let's handle devfs (ugh) names */
226 len = 0; 226 len = 0;
227 if (strncmp(cp, "ide/", 4) == 0) 227 if (is_prefixed_with(cp, "ide/"))
228 len = 4; 228 len = 4;
229 if (strncmp(cp, "scsi/", 5) == 0) 229 if (is_prefixed_with(cp, "scsi/"))
230 len = 5; 230 len = 5;
231 if (len) { 231 if (len) {
232 cp += len; 232 cp += len;
@@ -237,38 +237,38 @@ static char *base_device(const char *device)
237 * some number of digits at each level, abort. 237 * some number of digits at each level, abort.
238 */ 238 */
239 for (hier = devfs_hier; *hier; hier++) { 239 for (hier = devfs_hier; *hier; hier++) {
240 len = strlen(*hier); 240 cp = is_prefixed_with(cp, *hier);
241 if (strncmp(cp, *hier, len) != 0) 241 if (!cp)
242 goto errout; 242 goto errout;
243 cp += len; 243 while (*cp != '/' && *cp != '\0') {
244 while (*cp != '/' && *cp != 0) {
245 if (!isdigit(*cp)) 244 if (!isdigit(*cp))
246 goto errout; 245 goto errout;
247 cp++; 246 cp++;
248 } 247 }
248//FIXME: what if *cp = '\0' now? cp++ moves past it!!!
249 cp++; 249 cp++;
250 } 250 }
251 cp[-1] = 0; 251 cp[-1] = '\0';
252 return str; 252 return str;
253 } 253 }
254 254
255 /* Now handle devfs /dev/disc or /dev/disk names */ 255 /* Now handle devfs /dev/disc or /dev/disk names */
256 disk = 0; 256 disk = NULL;
257 if (strncmp(cp, "discs/", 6) == 0) 257 if (is_prefixed_with(cp, "discs/"))
258 disk = "disc"; 258 disk = "disc";
259 else if (strncmp(cp, "disks/", 6) == 0) 259 else if (is_prefixed_with(cp, "disks/"))
260 disk = "disk"; 260 disk = "disk";
261 if (disk) { 261 if (disk) {
262 cp += 6; 262 cp += 6;
263 if (strncmp(cp, disk, 4) != 0) 263 cp = is_prefixed_with(cp, disk);
264 if (!cp)
264 goto errout; 265 goto errout;
265 cp += 4; 266 while (*cp != '/' && *cp != '\0') {
266 while (*cp != '/' && *cp != 0) {
267 if (!isdigit(*cp)) 267 if (!isdigit(*cp))
268 goto errout; 268 goto errout;
269 cp++; 269 cp++;
270 } 270 }
271 *cp = 0; 271 *cp = '\0';
272 return str; 272 return str;
273 } 273 }
274#endif 274#endif
@@ -593,8 +593,8 @@ static void fsck_device(struct fs_info *fs /*, int interactive */)
593 type, "from fstab"); 593 type, "from fstab");
594 } else if (fstype 594 } else if (fstype
595 && (fstype[0] != 'n' || fstype[1] != 'o') /* != "no" */ 595 && (fstype[0] != 'n' || fstype[1] != 'o') /* != "no" */
596 && strncmp(fstype, "opts=", 5) != 0 596 && !is_prefixed_with(fstype, "opts=")
597 && strncmp(fstype, "loop", 4) != 0 597 && !is_prefixed_with(fstype, "loop")
598 && !strchr(fstype, ',') 598 && !strchr(fstype, ',')
599 ) { 599 ) {
600 type = fstype; 600 type = fstype;
@@ -627,8 +627,8 @@ static int device_already_active(char *device)
627#ifdef BASE_MD 627#ifdef BASE_MD
628 /* Don't check a soft raid disk with any other disk */ 628 /* Don't check a soft raid disk with any other disk */
629 if (instance_list 629 if (instance_list
630 && (!strncmp(instance_list->device, BASE_MD, sizeof(BASE_MD)-1) 630 && (is_prefixed_with(instance_list->device, BASE_MD)
631 || !strncmp(device, BASE_MD, sizeof(BASE_MD)-1)) 631 || is_prefixed_with(device, BASE_MD))
632 ) { 632 ) {
633 return 1; 633 return 1;
634 } 634 }
@@ -895,7 +895,7 @@ static void compile_fs_type(char *fs_type)
895 if (strcmp(s, "loop") == 0) 895 if (strcmp(s, "loop") == 0)
896 /* loop is really short-hand for opts=loop */ 896 /* loop is really short-hand for opts=loop */
897 goto loop_special_case; 897 goto loop_special_case;
898 if (strncmp(s, "opts=", 5) == 0) { 898 if (is_prefixed_with(s, "opts=")) {
899 s += 5; 899 s += 5;
900 loop_special_case: 900 loop_special_case:
901 fs_type_flag[num] = negate ? FS_TYPE_FLAG_NEGOPT : FS_TYPE_FLAG_OPT; 901 fs_type_flag[num] = negate ? FS_TYPE_FLAG_NEGOPT : FS_TYPE_FLAG_OPT;
diff --git a/editors/patch.c b/editors/patch.c
index f86067544..cb25e4140 100644
--- a/editors/patch.c
+++ b/editors/patch.c
@@ -414,7 +414,7 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
414 } 414 }
415 415
416 // Open a new file? 416 // Open a new file?
417 if (!strncmp("--- ", patchline, 4) || !strncmp("+++ ", patchline, 4)) { 417 if (is_prefixed_with(patchline, "--- ") || is_prefixed_with(patchline, "+++ ")) {
418 char *s, **name = reverse ? &newname : &oldname; 418 char *s, **name = reverse ? &newname : &oldname;
419 int i; 419 int i;
420 420
@@ -446,7 +446,7 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
446 446
447 // Start a new hunk? Usually @@ -oldline,oldlen +newline,newlen @@ 447 // Start a new hunk? Usually @@ -oldline,oldlen +newline,newlen @@
448 // but a missing ,value means the value is 1. 448 // but a missing ,value means the value is 1.
449 } else if (state == 1 && !strncmp("@@ -", patchline, 4)) { 449 } else if (state == 1 && is_prefixed_with(patchline, "@@ -")) {
450 int i; 450 int i;
451 char *s = patchline+4; 451 char *s = patchline+4;
452 452
diff --git a/include/libbb.h b/include/libbb.h
index be792d6b2..c97df6047 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -389,6 +389,7 @@ const char *bb_basename(const char *name) FAST_FUNC;
389/* NB: can violate const-ness (similarly to strchr) */ 389/* NB: can violate const-ness (similarly to strchr) */
390char *last_char_is(const char *s, int c) FAST_FUNC; 390char *last_char_is(const char *s, int c) FAST_FUNC;
391const char* endofname(const char *name) FAST_FUNC; 391const char* endofname(const char *name) FAST_FUNC;
392char *is_prefixed_with(const char *string, const char *key) FAST_FUNC;
392 393
393int ndelay_on(int fd) FAST_FUNC; 394int ndelay_on(int fd) FAST_FUNC;
394int ndelay_off(int fd) FAST_FUNC; 395int ndelay_off(int fd) FAST_FUNC;
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 54300bd87..8fd8fd525 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -193,7 +193,7 @@ void lbb_prepare(const char *applet
193 if (argv[1] 193 if (argv[1]
194 && !argv[2] 194 && !argv[2]
195 && strcmp(argv[1], "--help") == 0 195 && strcmp(argv[1], "--help") == 0
196 && strncmp(applet, "busybox", 7) != 0 196 && !is_prefixed_with(applet, "busybox")
197 ) { 197 ) {
198 /* Special case. POSIX says "test --help" 198 /* Special case. POSIX says "test --help"
199 * should be no different from e.g. "test --foo". */ 199 * should be no different from e.g. "test --foo". */
@@ -673,7 +673,7 @@ static int busybox_main(char **argv)
673 return 0; 673 return 0;
674 } 674 }
675 675
676 if (strncmp(argv[1], "--list", 6) == 0) { 676 if (is_prefixed_with(argv[1], "--list")) {
677 unsigned i = 0; 677 unsigned i = 0;
678 const char *a = applet_names; 678 const char *a = applet_names;
679 dup2(1, 2); 679 dup2(1, 2);
@@ -778,7 +778,7 @@ void FAST_FUNC run_applet_and_exit(const char *name, char **argv)
778 int applet = find_applet_by_name(name); 778 int applet = find_applet_by_name(name);
779 if (applet >= 0) 779 if (applet >= 0)
780 run_applet_no_and_exit(applet, argv); 780 run_applet_no_and_exit(applet, argv);
781 if (strncmp(name, "busybox", 7) == 0) 781 if (is_prefixed_with(name, "busybox"))
782 exit(busybox_main(argv)); 782 exit(busybox_main(argv));
783} 783}
784 784
@@ -817,7 +817,7 @@ int main(int argc UNUSED_PARAM, char **argv)
817 817
818#if defined(SINGLE_APPLET_MAIN) 818#if defined(SINGLE_APPLET_MAIN)
819 /* Only one applet is selected in .config */ 819 /* Only one applet is selected in .config */
820 if (argv[1] && strncmp(argv[0], "busybox", 7) == 0) { 820 if (argv[1] && is_prefixed_with(argv[0], "busybox")) {
821 /* "busybox <applet> <params>" should still work as expected */ 821 /* "busybox <applet> <params>" should still work as expected */
822 argv++; 822 argv++;
823 } 823 }
diff --git a/libbb/compare_string_array.c b/libbb/compare_string_array.c
index 4b10cc138..e24815a03 100644
--- a/libbb/compare_string_array.c
+++ b/libbb/compare_string_array.c
@@ -5,6 +5,24 @@
5 5
6#include "libbb.h" 6#include "libbb.h"
7 7
8char* FAST_FUNC is_prefixed_with(const char *string, const char *key)
9{
10#if 0 /* Two passes over key - probably slower */
11 int len = strlen(key);
12 if (strncmp(string, key, len) == 0)
13 return string + len;
14 return NULL;
15#else /* Open-coded */
16 while (*key != '\0') {
17 if (*key != *string)
18 return NULL;
19 key++;
20 string++;
21 }
22 return (char*)string;
23#endif
24}
25
8/* returns the array index of the string */ 26/* returns the array index of the string */
9/* (index of first match is returned, or -1) */ 27/* (index of first match is returned, or -1) */
10int FAST_FUNC index_in_str_array(const char *const string_array[], const char *key) 28int 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)
39int FAST_FUNC index_in_substr_array(const char *const string_array[], const char *key) 57int FAST_FUNC index_in_substr_array(const char *const string_array[], const char *key)
40{ 58{
41 int i; 59 int i;
42 int len = strlen(key); 60 if (key[0]) {
43 if (len) {
44 for (i = 0; string_array[i] != 0; i++) { 61 for (i = 0; string_array[i] != 0; i++) {
45 if (strncmp(string_array[i], key, len) == 0) { 62 if (is_prefixed_with(string_array[i], key)) {
46 return i; 63 return i;
47 } 64 }
48 } 65 }
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 249b401b4..a83e07c0c 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -681,7 +681,7 @@ static NOINLINE unsigned complete_username(const char *ud)
681 setpwent(); 681 setpwent();
682 while ((pw = getpwent()) != NULL) { 682 while ((pw = getpwent()) != NULL) {
683 /* Null usernames should result in all users as possible completions. */ 683 /* Null usernames should result in all users as possible completions. */
684 if (/*!userlen || */ strncmp(ud, pw->pw_name, userlen) == 0) { 684 if (/* !ud[0] || */ is_prefixed_with(pw->pw_name, ud)) {
685 add_match(xasprintf("~%s/", pw->pw_name)); 685 add_match(xasprintf("~%s/", pw->pw_name));
686 } 686 }
687 } 687 }
@@ -792,7 +792,7 @@ static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type)
792 if (!pfind[0] && DOT_OR_DOTDOT(name_found)) 792 if (!pfind[0] && DOT_OR_DOTDOT(name_found))
793 continue; 793 continue;
794 /* match? */ 794 /* match? */
795 if (strncmp(name_found, pfind, pf_len) != 0) 795 if (!is_prefixed_with(name_found, pfind))
796 continue; /* no */ 796 continue; /* no */
797 797
798 found = concat_path_file(paths[i], name_found); 798 found = concat_path_file(paths[i], name_found);
@@ -1879,15 +1879,16 @@ static void parse_and_put_prompt(const char *prmt_ptr)
1879 cwd_buf = xrealloc_getcwd_or_warn(NULL); 1879 cwd_buf = xrealloc_getcwd_or_warn(NULL);
1880 if (!cwd_buf) 1880 if (!cwd_buf)
1881 cwd_buf = (char *)bb_msg_unknown; 1881 cwd_buf = (char *)bb_msg_unknown;
1882 else { 1882 else if (home_pwd_buf[0]) {
1883 char *after_home_user;
1884
1883 /* /home/user[/something] -> ~[/something] */ 1885 /* /home/user[/something] -> ~[/something] */
1884 l = strlen(home_pwd_buf); 1886 after_home_user = is_prefixed_with(cwd_buf, home_pwd_buf);
1885 if (l != 0 1887 if (after_home_user
1886 && strncmp(home_pwd_buf, cwd_buf, l) == 0 1888 && (*after_home_user == '/' || *after_home_user == '\0')
1887 && (cwd_buf[l] == '/' || cwd_buf[l] == '\0')
1888 ) { 1889 ) {
1889 cwd_buf[0] = '~'; 1890 cwd_buf[0] = '~';
1890 overlapping_strcpy(cwd_buf + 1, cwd_buf + l); 1891 overlapping_strcpy(cwd_buf + 1, after_home_user);
1891 } 1892 }
1892 } 1893 }
1893 } 1894 }
diff --git a/libbb/match_fstype.c b/libbb/match_fstype.c
index 32c3d7f18..b066b4211 100644
--- a/libbb/match_fstype.c
+++ b/libbb/match_fstype.c
@@ -17,7 +17,6 @@
17int FAST_FUNC match_fstype(const struct mntent *mt, const char *t_fstype) 17int FAST_FUNC match_fstype(const struct mntent *mt, const char *t_fstype)
18{ 18{
19 int match = 1; 19 int match = 1;
20 int len;
21 20
22 if (!t_fstype) 21 if (!t_fstype)
23 return match; 22 return match;
@@ -27,10 +26,10 @@ int FAST_FUNC match_fstype(const struct mntent *mt, const char *t_fstype)
27 t_fstype += 2; 26 t_fstype += 2;
28 } 27 }
29 28
30 len = strlen(mt->mnt_type);
31 while (1) { 29 while (1) {
32 if (strncmp(mt->mnt_type, t_fstype, len) == 0 30 char *after_mnt_type = is_prefixed_with(t_fstype, mt->mnt_type);
33 && (t_fstype[len] == '\0' || t_fstype[len] == ',') 31 if (after_mnt_type
32 && (*after_mnt_type == '\0' || *after_mnt_type == ',')
34 ) { 33 ) {
35 return match; 34 return match;
36 } 35 }
diff --git a/libbb/procps.c b/libbb/procps.c
index 5b68d3431..948b91ee6 100644
--- a/libbb/procps.c
+++ b/libbb/procps.c
@@ -205,11 +205,11 @@ int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total,
205 // Rss: nnn kB 205 // Rss: nnn kB
206 // ..... 206 // .....
207 207
208 char *tp = buf, *p; 208 char *tp, *p;
209 209
210#define SCAN(S, X) \ 210#define SCAN(S, X) \
211 if (strncmp(tp, S, sizeof(S)-1) == 0) { \ 211 if ((tp = is_prefixed_with(buf, S)) != NULL) { \
212 tp = skip_whitespace(tp + sizeof(S)-1); \ 212 tp = skip_whitespace(tp); \
213 total->X += currec.X = fast_strtoul_10(&tp); \ 213 total->X += currec.X = fast_strtoul_10(&tp); \
214 continue; \ 214 continue; \
215 } 215 }
@@ -247,7 +247,7 @@ int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total,
247 // skipping "rw-s FILEOFS M:m INODE " 247 // skipping "rw-s FILEOFS M:m INODE "
248 tp = skip_whitespace(skip_fields(tp, 4)); 248 tp = skip_whitespace(skip_fields(tp, 4));
249 // filter out /dev/something (something != zero) 249 // filter out /dev/something (something != zero)
250 if (strncmp(tp, "/dev/", 5) != 0 || strcmp(tp, "/dev/zero\n") == 0) { 250 if (!is_prefixed_with(tp, "/dev/") || strcmp(tp, "/dev/zero\n") == 0) {
251 if (currec.smap_mode[1] == 'w') { 251 if (currec.smap_mode[1] == 'w') {
252 currec.mapped_rw = currec.smap_size; 252 currec.mapped_rw = currec.smap_size;
253 total->mapped_rw += currec.smap_size; 253 total->mapped_rw += currec.smap_size;
@@ -497,8 +497,8 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
497 while (fgets(buf, sizeof(buf), file)) { 497 while (fgets(buf, sizeof(buf), file)) {
498 char *tp; 498 char *tp;
499#define SCAN_TWO(str, name, statement) \ 499#define SCAN_TWO(str, name, statement) \
500 if (strncmp(buf, str, sizeof(str)-1) == 0) { \ 500 if ((tp = is_prefixed_with(buf, str)) != NULL) { \
501 tp = skip_whitespace(buf + sizeof(str)-1); \ 501 tp = skip_whitespace(tp); \
502 sscanf(tp, "%u", &sp->name); \ 502 sscanf(tp, "%u", &sp->name); \
503 statement; \ 503 statement; \
504 } 504 }
diff --git a/libbb/rtc.c b/libbb/rtc.c
index 6d06d57f9..c4117ba34 100644
--- a/libbb/rtc.c
+++ b/libbb/rtc.c
@@ -22,7 +22,7 @@ int FAST_FUNC rtc_adjtime_is_utc(void)
22 char buffer[128]; 22 char buffer[128];
23 23
24 while (fgets(buffer, sizeof(buffer), f)) { 24 while (fgets(buffer, sizeof(buffer), f)) {
25 if (strncmp(buffer, "UTC", 3) == 0) { 25 if (is_prefixed_with(buffer, "UTC")) {
26 utc = 1; 26 utc = 1;
27 break; 27 break;
28 } 28 }
diff --git a/libbb/skip_whitespace.c b/libbb/skip_whitespace.c
index 8c7b674c3..b6cfbba4d 100644
--- a/libbb/skip_whitespace.c
+++ b/libbb/skip_whitespace.c
@@ -33,7 +33,7 @@ char* FAST_FUNC skip_non_whitespace(const char *s)
33 33
34char* FAST_FUNC skip_dev_pfx(const char *tty_name) 34char* FAST_FUNC skip_dev_pfx(const char *tty_name)
35{ 35{
36 if (strncmp(tty_name, "/dev/", 5) == 0) 36 if (is_prefixed_with(tty_name, "/dev/"))
37 tty_name += 5; 37 tty_name += 5;
38 return (char*)tty_name; 38 return (char*)tty_name;
39} 39}
diff --git a/libbb/update_passwd.c b/libbb/update_passwd.c
index dc26ebd1d..a2004f480 100644
--- a/libbb/update_passwd.c
+++ b/libbb/update_passwd.c
@@ -84,7 +84,6 @@ int FAST_FUNC update_passwd(const char *filename,
84 char *fnamesfx; 84 char *fnamesfx;
85 char *sfx_char; 85 char *sfx_char;
86 char *name_colon; 86 char *name_colon;
87 unsigned user_len;
88 int old_fd; 87 int old_fd;
89 int new_fd; 88 int new_fd;
90 int i; 89 int i;
@@ -108,7 +107,6 @@ int FAST_FUNC update_passwd(const char *filename,
108 fnamesfx = xasprintf("%s+", filename); 107 fnamesfx = xasprintf("%s+", filename);
109 sfx_char = &fnamesfx[strlen(fnamesfx)-1]; 108 sfx_char = &fnamesfx[strlen(fnamesfx)-1];
110 name_colon = xasprintf("%s:", name ? name : ""); 109 name_colon = xasprintf("%s:", name ? name : "");
111 user_len = strlen(name_colon);
112 110
113 if (shadow) 111 if (shadow)
114 old_fp = fopen(filename, "r+"); 112 old_fp = fopen(filename, "r+");
@@ -179,7 +177,7 @@ int FAST_FUNC update_passwd(const char *filename,
179 while (list) { 177 while (list) {
180 list++; 178 list++;
181 next_list_element: 179 next_list_element:
182 if (strncmp(list, member, member_len) == 0) { 180 if (is_prefixed_with(list, member)) {
183 char c; 181 char c;
184 changed_lines++; 182 changed_lines++;
185 c = list[member_len]; 183 c = list[member_len];
@@ -201,13 +199,14 @@ int FAST_FUNC update_passwd(const char *filename,
201 goto next; 199 goto next;
202 } 200 }
203 201
204 if (strncmp(name_colon, line, user_len) != 0) { 202 cp = is_prefixed_with(line, name_colon);
203 if (!cp) {
205 fprintf(new_fp, "%s\n", line); 204 fprintf(new_fp, "%s\n", line);
206 goto next; 205 goto next;
207 } 206 }
208 207
209 /* We have a match with "name:"... */ 208 /* We have a match with "name:"... */
210 cp = line + user_len; /* move past name: */ 209 /* cp points past "name:" */
211 210
212#if ENABLE_FEATURE_ADDUSER_TO_GROUP || ENABLE_FEATURE_DEL_USER_FROM_GROUP 211#if ENABLE_FEATURE_ADDUSER_TO_GROUP || ENABLE_FEATURE_DEL_USER_FROM_GROUP
213 if (member) { 212 if (member) {
diff --git a/libbb/xconnect.c b/libbb/xconnect.c
index 1c8bb2b73..2a96e03dc 100644
--- a/libbb/xconnect.c
+++ b/libbb/xconnect.c
@@ -171,7 +171,7 @@ IF_NOT_FEATURE_IPV6(sa_family_t af = AF_INET;)
171 const char *cp; 171 const char *cp;
172 struct addrinfo hint; 172 struct addrinfo hint;
173 173
174 if (ENABLE_FEATURE_UNIX_LOCAL && strncmp(host, "local:", 6) == 0) { 174 if (ENABLE_FEATURE_UNIX_LOCAL && is_prefixed_with(host, "local:")) {
175 struct sockaddr_un *sun; 175 struct sockaddr_un *sun;
176 176
177 r = xzalloc(LSA_LEN_SIZE + sizeof(struct sockaddr_un)); 177 r = xzalloc(LSA_LEN_SIZE + sizeof(struct sockaddr_un));
diff --git a/miscutils/crond.c b/miscutils/crond.c
index 3659b9a6f..eb327f855 100644
--- a/miscutils/crond.c
+++ b/miscutils/crond.c
@@ -438,14 +438,14 @@ static void load_crontab(const char *fileName)
438 log5("user:%s entry:%s", fileName, parser->data); 438 log5("user:%s entry:%s", fileName, parser->data);
439 439
440 /* check if line is setting MAILTO= */ 440 /* check if line is setting MAILTO= */
441 if (0 == strncmp(tokens[0], "MAILTO=", 7)) { 441 if (is_prefixed_with(tokens[0], "MAILTO=")) {
442#if ENABLE_FEATURE_CROND_CALL_SENDMAIL 442#if ENABLE_FEATURE_CROND_CALL_SENDMAIL
443 free(mailTo); 443 free(mailTo);
444 mailTo = (tokens[0][7]) ? xstrdup(&tokens[0][7]) : NULL; 444 mailTo = (tokens[0][7]) ? xstrdup(&tokens[0][7]) : NULL;
445#endif /* otherwise just ignore such lines */ 445#endif /* otherwise just ignore such lines */
446 continue; 446 continue;
447 } 447 }
448 if (0 == strncmp(tokens[0], "SHELL=", 6)) { 448 if (is_prefixed_with(tokens[0], "SHELL=")) {
449 free(shell); 449 free(shell);
450 shell = xstrdup(&tokens[0][6]); 450 shell = xstrdup(&tokens[0][6]);
451 continue; 451 continue;
diff --git a/miscutils/dc.c b/miscutils/dc.c
index a7bd360d2..f94d6fa6b 100644
--- a/miscutils/dc.c
+++ b/miscutils/dc.c
@@ -244,9 +244,9 @@ static void stack_machine(const char *argument)
244 244
245 o = operators; 245 o = operators;
246 do { 246 do {
247 const size_t name_len = strlen(o->name); 247 char *after_name = is_prefixed_with(argument, o->name);
248 if (strncmp(o->name, argument, name_len) == 0) { 248 if (after_name) {
249 argument += name_len; 249 argument = after_name;
250 o->function(); 250 o->function();
251 goto next; 251 goto next;
252 } 252 }
diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c
index 96ffe0738..5a6aec6bd 100644
--- a/miscutils/devfsd.c
+++ b/miscutils/devfsd.c
@@ -1405,7 +1405,6 @@ const char *get_old_name(const char *devname, unsigned int namelen,
1405 int indexx; 1405 int indexx;
1406 const char *pty1; 1406 const char *pty1;
1407 const char *pty2; 1407 const char *pty2;
1408 size_t len;
1409 /* 1 to 5 "scsi/" , 6 to 9 "ide/host", 10 sbp/, 11 vcc/, 12 pty/ */ 1408 /* 1 to 5 "scsi/" , 6 to 9 "ide/host", 10 sbp/, 11 vcc/, 12 pty/ */
1410 static const char *const fmt[] = { 1409 static const char *const fmt[] = {
1411 NULL , 1410 NULL ,
@@ -1425,12 +1424,11 @@ const char *get_old_name(const char *devname, unsigned int namelen,
1425 }; 1424 };
1426 1425
1427 for (trans = translate_table; trans->match != NULL; ++trans) { 1426 for (trans = translate_table; trans->match != NULL; ++trans) {
1428 len = strlen(trans->match); 1427 char *after_match = is_prefixed_with(devname, trans->match);
1429 1428 if (after_match) {
1430 if (strncmp(devname, trans->match, len) == 0) {
1431 if (trans->format == NULL) 1429 if (trans->format == NULL)
1432 return devname + len; 1430 return after_match;
1433 sprintf(buffer, trans->format, devname + len); 1431 sprintf(buffer, trans->format, after_match);
1434 return buffer; 1432 return buffer;
1435 } 1433 }
1436 } 1434 }
diff --git a/miscutils/fbsplash.c b/miscutils/fbsplash.c
index 7b695b26f..77033c258 100644
--- a/miscutils/fbsplash.c
+++ b/miscutils/fbsplash.c
@@ -516,7 +516,7 @@ int fbsplash_main(int argc UNUSED_PARAM, char **argv)
516 // handle a case when we have many buffered lines 516 // handle a case when we have many buffered lines
517 // already in the pipe 517 // already in the pipe
518 while ((num_buf = xmalloc_fgetline(fp)) != NULL) { 518 while ((num_buf = xmalloc_fgetline(fp)) != NULL) {
519 if (strncmp(num_buf, "exit", 4) == 0) { 519 if (is_prefixed_with(num_buf, "exit")) {
520 DEBUG_MESSAGE("exit"); 520 DEBUG_MESSAGE("exit");
521 break; 521 break;
522 } 522 }
diff --git a/miscutils/i2c_tools.c b/miscutils/i2c_tools.c
index 90d1e1e14..03bb03974 100644
--- a/miscutils/i2c_tools.c
+++ b/miscutils/i2c_tools.c
@@ -1198,7 +1198,7 @@ static void NORETURN list_i2c_busses_and_exit(void)
1198 if (subde->d_name[0] == '.') 1198 if (subde->d_name[0] == '.')
1199 continue; 1199 continue;
1200 1200
1201 if (strncmp(subde->d_name, "i2c-", 4) == 0) { 1201 if (is_prefixed_with(subde->d_name, "i2c-")) {
1202 snprintf(path, NAME_MAX, 1202 snprintf(path, NAME_MAX,
1203 "%s/%s/device/%s/name", 1203 "%s/%s/device/%s/name",
1204 i2cdev_path, de->d_name, 1204 i2cdev_path, de->d_name,
@@ -1229,7 +1229,7 @@ found:
1229 if (rv != 1) 1229 if (rv != 1)
1230 continue; 1230 continue;
1231 1231
1232 if (strncmp(name, "ISA", 3) == 0) 1232 if (is_prefixed_with(name, "ISA"))
1233 adt = ADT_ISA; 1233 adt = ADT_ISA;
1234 else 1234 else
1235 adt = i2cdetect_get_funcs(bus); 1235 adt = i2cdetect_get_funcs(bus);
diff --git a/miscutils/last.c b/miscutils/last.c
index 24f6e1c78..a144c7e47 100644
--- a/miscutils/last.c
+++ b/miscutils/last.c
@@ -87,11 +87,11 @@ int last_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
87 if (++n > 0) 87 if (++n > 0)
88 ut.ut_type = n != 3 ? n : SHUTDOWN_TIME; 88 ut.ut_type = n != 3 ? n : SHUTDOWN_TIME;
89#else 89#else
90 if (strncmp(ut.ut_user, "shutdown", 8) == 0) 90 if (is_prefixed_with(ut.ut_user, "shutdown"))
91 ut.ut_type = SHUTDOWN_TIME; 91 ut.ut_type = SHUTDOWN_TIME;
92 else if (strncmp(ut.ut_user, "reboot", 6) == 0) 92 else if (is_prefixed_with(ut.ut_user, "reboot"))
93 ut.ut_type = BOOT_TIME; 93 ut.ut_type = BOOT_TIME;
94 else if (strncmp(ut.ut_user, "runlevel", 8) == 0) 94 else if (is_prefixed_with(ut.ut_user, "runlevel"))
95 ut.ut_type = RUN_LVL; 95 ut.ut_type = RUN_LVL;
96#endif 96#endif
97 } else { 97 } else {
diff --git a/miscutils/man.c b/miscutils/man.c
index c39870e67..58ed81955 100644
--- a/miscutils/man.c
+++ b/miscutils/man.c
@@ -66,7 +66,7 @@ static int run_pipe(const char *pager, char *man_filename, int man, int level)
66 goto ordinary_manpage; 66 goto ordinary_manpage;
67 67
68 line = xmalloc_open_zipped_read_close(man_filename, NULL); 68 line = xmalloc_open_zipped_read_close(man_filename, NULL);
69 if (!line || strncmp(line, ".so ", 4) != 0) { 69 if (!line || !is_prefixed_with(line, ".so ")) {
70 free(line); 70 free(line);
71 goto ordinary_manpage; 71 goto ordinary_manpage;
72 } 72 }
@@ -228,7 +228,7 @@ int man_main(int argc UNUSED_PARAM, char **argv)
228 if (!token[1]) 228 if (!token[1])
229 continue; 229 continue;
230 if (strcmp("DEFINE", token[0]) == 0) { 230 if (strcmp("DEFINE", token[0]) == 0) {
231 if (strncmp("pager", token[1], 5) == 0) { 231 if (is_prefixed_with("pager", token[1])) {
232 pager = xstrdup(skip_whitespace(token[1]) + 5); 232 pager = xstrdup(skip_whitespace(token[1]) + 5);
233 } 233 }
234 } else 234 } else
diff --git a/modutils/depmod.c b/modutils/depmod.c
index 37a8482d9..9713aef92 100644
--- a/modutils/depmod.c
+++ b/modutils/depmod.c
@@ -55,7 +55,7 @@ static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARA
55 NULL 55 NULL
56 ); 56 );
57 for (ptr = image; ptr < image + len - 10; ptr++) { 57 for (ptr = image; ptr < image + len - 10; ptr++) {
58 if (strncmp(ptr, "depends=", 8) == 0) { 58 if (is_prefixed_with(ptr, "depends=")) {
59 char *u; 59 char *u;
60 60
61 ptr += 8; 61 ptr += 8;
@@ -64,15 +64,15 @@ static int FAST_FUNC parse_module(const char *fname, struct stat *sb UNUSED_PARA
64 *u = '_'; 64 *u = '_';
65 ptr += string_to_llist(ptr, &info->dependencies, ","); 65 ptr += string_to_llist(ptr, &info->dependencies, ",");
66 } else if (ENABLE_FEATURE_MODUTILS_ALIAS 66 } else if (ENABLE_FEATURE_MODUTILS_ALIAS
67 && strncmp(ptr, "alias=", 6) == 0 67 && is_prefixed_with(ptr, "alias=")
68 ) { 68 ) {
69 llist_add_to(&info->aliases, xstrdup(ptr + 6)); 69 llist_add_to(&info->aliases, xstrdup(ptr + 6));
70 ptr += strlen(ptr); 70 ptr += strlen(ptr);
71 } else if (ENABLE_FEATURE_MODUTILS_SYMBOLS 71 } else if (ENABLE_FEATURE_MODUTILS_SYMBOLS
72 && strncmp(ptr, "__ksymtab_", 10) == 0 72 && is_prefixed_with(ptr, "__ksymtab_")
73 ) { 73 ) {
74 ptr += 10; 74 ptr += 10;
75 if (strncmp(ptr, "gpl", 3) == 0 75 if (is_prefixed_with(ptr, "gpl")
76 || strcmp(ptr, "strings") == 0 76 || strcmp(ptr, "strings") == 0
77 ) { 77 ) {
78 continue; 78 continue;
diff --git a/modutils/modinfo.c b/modutils/modinfo.c
index ee379304c..8e74b6438 100644
--- a/modutils/modinfo.c
+++ b/modutils/modinfo.c
@@ -62,7 +62,7 @@ static void modinfo(const char *path, const char *version,
62 "firmware", 62 "firmware",
63 }; 63 };
64 size_t len; 64 size_t len;
65 int j, length; 65 int j;
66 char *ptr, *the_module; 66 char *ptr, *the_module;
67 const char *field = env->field; 67 const char *field = env->field;
68 int tags = env->tags; 68 int tags = env->tags;
@@ -94,16 +94,18 @@ static void modinfo(const char *path, const char *version,
94 pattern = field; 94 pattern = field;
95 if ((1<<j) & OPT_TAGS) 95 if ((1<<j) & OPT_TAGS)
96 pattern = shortcuts[j]; 96 pattern = shortcuts[j];
97 length = strlen(pattern);
98 ptr = the_module; 97 ptr = the_module;
99 while (1) { 98 while (1) {
99 char *after_pattern;
100
100 ptr = memchr(ptr, *pattern, len - (ptr - (char*)the_module)); 101 ptr = memchr(ptr, *pattern, len - (ptr - (char*)the_module));
101 if (ptr == NULL) /* no occurance left, done */ 102 if (ptr == NULL) /* no occurance left, done */
102 break; 103 break;
103 if (strncmp(ptr, pattern, length) == 0 && ptr[length] == '=') { 104 after_pattern = is_prefixed_with(ptr, pattern);
105 if (after_pattern && *after_pattern == '=') {
104 /* field prefixes are 0x80 or 0x00 */ 106 /* field prefixes are 0x80 or 0x00 */
105 if ((ptr[-1] & 0x7F) == '\0') { 107 if ((ptr[-1] & 0x7F) == 0x00) {
106 ptr += length + 1; 108 ptr = after_pattern + 1;
107 display(ptr, pattern, (1<<j) != tags); 109 display(ptr, pattern, (1<<j) != tags);
108 ptr += strlen(ptr); 110 ptr += strlen(ptr);
109 } 111 }
diff --git a/modutils/modprobe-small.c b/modutils/modprobe-small.c
index ed177bb9b..9c941064b 100644
--- a/modutils/modprobe-small.c
+++ b/modutils/modprobe-small.c
@@ -116,21 +116,21 @@ static char* copy_stringbuf(void)
116 116
117static char* find_keyword(char *ptr, size_t len, const char *word) 117static char* find_keyword(char *ptr, size_t len, const char *word)
118{ 118{
119 int wlen;
120
121 if (!ptr) /* happens if xmalloc_open_zipped_read_close cannot read it */ 119 if (!ptr) /* happens if xmalloc_open_zipped_read_close cannot read it */
122 return NULL; 120 return NULL;
123 121
124 wlen = strlen(word); 122 len -= strlen(word) - 1;
125 len -= wlen - 1;
126 while ((ssize_t)len > 0) { 123 while ((ssize_t)len > 0) {
127 char *old = ptr; 124 char *old = ptr;
125 char *after_word;
126
128 /* search for the first char in word */ 127 /* search for the first char in word */
129 ptr = memchr(ptr, *word, len); 128 ptr = memchr(ptr, word[0], len);
130 if (ptr == NULL) /* no occurance left, done */ 129 if (ptr == NULL) /* no occurance left, done */
131 break; 130 break;
132 if (strncmp(ptr, word, wlen) == 0) 131 after_word = is_prefixed_with(ptr, word);
133 return ptr + wlen; /* found, return ptr past it */ 132 if (after_word)
133 return after_word; /* found, return ptr past it */
134 ++ptr; 134 ++ptr;
135 len -= (ptr - old); 135 len -= (ptr - old);
136 } 136 }
@@ -536,7 +536,7 @@ static module_info** find_alias(const char *alias)
536// TODO: open only once, invent config_rewind() 536// TODO: open only once, invent config_rewind()
537static int already_loaded(const char *name) 537static int already_loaded(const char *name)
538{ 538{
539 int ret, namelen; 539 int ret;
540 char *line; 540 char *line;
541 FILE *fp; 541 FILE *fp;
542 542
@@ -545,15 +545,16 @@ static int already_loaded(const char *name)
545 fp = fopen_for_read("/proc/modules"); 545 fp = fopen_for_read("/proc/modules");
546 if (!fp) 546 if (!fp)
547 return 0; 547 return 0;
548 namelen = strlen(name);
549 while ((line = xmalloc_fgetline(fp)) != NULL) { 548 while ((line = xmalloc_fgetline(fp)) != NULL) {
550 char *live; 549 char *live;
550 char *after_name;
551 551
552 // Examples from kernel 3.14.6: 552 // Examples from kernel 3.14.6:
553 //pcspkr 12718 0 - Live 0xffffffffa017e000 553 //pcspkr 12718 0 - Live 0xffffffffa017e000
554 //snd_timer 28690 2 snd_seq,snd_pcm, Live 0xffffffffa025e000 554 //snd_timer 28690 2 snd_seq,snd_pcm, Live 0xffffffffa025e000
555 //i915 801405 2 - Live 0xffffffffa0096000 555 //i915 801405 2 - Live 0xffffffffa0096000
556 if (strncmp(line, name, namelen) != 0 || line[namelen] != ' ') { 556 after_name = is_prefixed_with(line, name);
557 if (!after_name || *after_name != ' ') {
557 free(line); 558 free(line);
558 continue; 559 continue;
559 } 560 }
diff --git a/modutils/modprobe.c b/modutils/modprobe.c
index 0e8aa9e85..996de4074 100644
--- a/modutils/modprobe.c
+++ b/modutils/modprobe.c
@@ -260,7 +260,7 @@ static void add_probe(const char *name)
260 llist_add_to_end(&G.probes, m); 260 llist_add_to_end(&G.probes, m);
261 G.num_unresolved_deps++; 261 G.num_unresolved_deps++;
262 if (ENABLE_FEATURE_MODUTILS_SYMBOLS 262 if (ENABLE_FEATURE_MODUTILS_SYMBOLS
263 && strncmp(m->modname, "symbol:", 7) == 0 263 && is_prefixed_with(m->modname, "symbol:")
264 ) { 264 ) {
265 G.need_symbols = 1; 265 G.need_symbols = 1;
266 } 266 }
@@ -353,22 +353,18 @@ static char *parse_and_add_kcmdline_module_options(char *options, const char *mo
353 char *kcmdline_buf; 353 char *kcmdline_buf;
354 char *kcmdline; 354 char *kcmdline;
355 char *kptr; 355 char *kptr;
356 int len;
357 356
358 kcmdline_buf = xmalloc_open_read_close("/proc/cmdline", NULL); 357 kcmdline_buf = xmalloc_open_read_close("/proc/cmdline", NULL);
359 if (!kcmdline_buf) 358 if (!kcmdline_buf)
360 return options; 359 return options;
361 360
362 kcmdline = kcmdline_buf; 361 kcmdline = kcmdline_buf;
363 len = strlen(modulename);
364 while ((kptr = strsep(&kcmdline, "\n\t ")) != NULL) { 362 while ((kptr = strsep(&kcmdline, "\n\t ")) != NULL) {
365 if (strncmp(modulename, kptr, len) != 0) 363 char *after_modulename = is_prefixed_with(kptr, modulename);
366 continue; 364 if (!after_modulename || *after_modulename != '.')
367 kptr += len;
368 if (*kptr != '.')
369 continue; 365 continue;
370 /* It is "modulename.xxxx" */ 366 /* It is "modulename.xxxx" */
371 kptr++; 367 kptr = after_modulename + 1;
372 if (strchr(kptr, '=') != NULL) { 368 if (strchr(kptr, '=') != NULL) {
373 /* It is "modulename.opt=[val]" */ 369 /* It is "modulename.opt=[val]" */
374 options = gather_options_str(options, kptr); 370 options = gather_options_str(options, kptr);
diff --git a/modutils/modutils-24.c b/modutils/modutils-24.c
index 12cb75c54..fe46fc3fd 100644
--- a/modutils/modutils-24.c
+++ b/modutils/modutils-24.c
@@ -2255,7 +2255,7 @@ static int add_symbols_from(struct obj_file *f,
2255 * symbols so they cannot fudge it by adding the prefix on 2255 * symbols so they cannot fudge it by adding the prefix on
2256 * their references. 2256 * their references.
2257 */ 2257 */
2258 if (strncmp((char *)s->name, "GPLONLY_", 8) == 0) { 2258 if (is_prefixed_with((char *)s->name, "GPLONLY_")) {
2259#if ENABLE_FEATURE_CHECK_TAINTED_MODULE 2259#if ENABLE_FEATURE_CHECK_TAINTED_MODULE
2260 if (gpl) 2260 if (gpl)
2261 s->name += 8; 2261 s->name += 8;
diff --git a/networking/dnsd.c b/networking/dnsd.c
index fe98400f7..923ad6bc6 100644
--- a/networking/dnsd.c
+++ b/networking/dnsd.c
@@ -194,7 +194,7 @@ static char *table_lookup(struct dns_entry *d,
194 if ((len != 1 || d->name[1] != '*') 194 if ((len != 1 || d->name[1] != '*')
195 /* we assume (do not check) that query_string 195 /* we assume (do not check) that query_string
196 * ends in ".in-addr.arpa" */ 196 * ends in ".in-addr.arpa" */
197 && strncmp(d->rip, query_string, strlen(d->rip)) == 0 197 && is_prefixed_with(query_string, d->rip)
198 ) { 198 ) {
199#if DEBUG 199#if DEBUG
200 fprintf(stderr, "Found name:%s\n", d->name); 200 fprintf(stderr, "Found name:%s\n", d->name);
diff --git a/networking/httpd.c b/networking/httpd.c
index 9cf080401..7a9065fcc 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -697,7 +697,7 @@ static void parse_conf(const char *path, int flag)
697 goto config_error; 697 goto config_error;
698 } 698 }
699 *host_port++ = '\0'; 699 *host_port++ = '\0';
700 if (strncmp(host_port, "http://", 7) == 0) 700 if (is_prefixed_with(host_port, "http://"))
701 host_port += 7; 701 host_port += 7;
702 if (*host_port == '\0') { 702 if (*host_port == '\0') {
703 goto config_error; 703 goto config_error;
@@ -1894,7 +1894,7 @@ static Htaccess_Proxy *find_proxy_entry(const char *url)
1894{ 1894{
1895 Htaccess_Proxy *p; 1895 Htaccess_Proxy *p;
1896 for (p = proxy; p; p = p->next) { 1896 for (p = proxy; p; p = p->next) {
1897 if (strncmp(url, p->url_from, strlen(p->url_from)) == 0) 1897 if (is_prefixed_with(url, p->url_from))
1898 return p; 1898 return p;
1899 } 1899 }
1900 return NULL; 1900 return NULL;
@@ -2183,7 +2183,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
2183 if (STRNCASECMP(iobuf, "Range:") == 0) { 2183 if (STRNCASECMP(iobuf, "Range:") == 0) {
2184 /* We know only bytes=NNN-[MMM] */ 2184 /* We know only bytes=NNN-[MMM] */
2185 char *s = skip_whitespace(iobuf + sizeof("Range:")-1); 2185 char *s = skip_whitespace(iobuf + sizeof("Range:")-1);
2186 if (strncmp(s, "bytes=", 6) == 0) { 2186 if (is_prefixed_with(s, "bytes=") == 0) {
2187 s += sizeof("bytes=")-1; 2187 s += sizeof("bytes=")-1;
2188 range_start = BB_STRTOOFF(s, &s, 10); 2188 range_start = BB_STRTOOFF(s, &s, 10);
2189 if (s[0] != '-' || range_start < 0) { 2189 if (s[0] != '-' || range_start < 0) {
@@ -2269,7 +2269,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
2269 tptr = urlcopy + 1; /* skip first '/' */ 2269 tptr = urlcopy + 1; /* skip first '/' */
2270 2270
2271#if ENABLE_FEATURE_HTTPD_CGI 2271#if ENABLE_FEATURE_HTTPD_CGI
2272 if (strncmp(tptr, "cgi-bin/", 8) == 0) { 2272 if (is_prefixed_with(tptr, "cgi-bin/")) {
2273 if (tptr[8] == '\0') { 2273 if (tptr[8] == '\0') {
2274 /* protect listing "cgi-bin/" */ 2274 /* protect listing "cgi-bin/" */
2275 send_headers_and_exit(HTTP_FORBIDDEN); 2275 send_headers_and_exit(HTTP_FORBIDDEN);
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index c35d97a1a..daabeec0c 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -289,7 +289,7 @@ static char *parse(const char *command, struct interface_defn_t *ifd)
289 /* "hwaddress <class> <address>": 289 /* "hwaddress <class> <address>":
290 * unlike ifconfig, ip doesnt want <class> 290 * unlike ifconfig, ip doesnt want <class>
291 * (usually "ether" keyword). Skip it. */ 291 * (usually "ether" keyword). Skip it. */
292 if (strncmp(command, "hwaddress", 9) == 0) { 292 if (is_prefixed_with(command, "hwaddress")) {
293 varvalue = skip_whitespace(skip_non_whitespace(varvalue)); 293 varvalue = skip_whitespace(skip_non_whitespace(varvalue));
294 } 294 }
295# endif 295# endif
@@ -298,7 +298,7 @@ static char *parse(const char *command, struct interface_defn_t *ifd)
298# if ENABLE_FEATURE_IFUPDOWN_IP 298# if ENABLE_FEATURE_IFUPDOWN_IP
299 /* Sigh... Add a special case for 'ip' to convert from 299 /* Sigh... Add a special case for 'ip' to convert from
300 * dotted quad to bit count style netmasks. */ 300 * dotted quad to bit count style netmasks. */
301 if (strncmp(command, "bnmask", 6) == 0) { 301 if (is_prefixed_with(command, "bnmask")) {
302 unsigned res; 302 unsigned res;
303 varvalue = get_var("netmask", 7, ifd); 303 varvalue = get_var("netmask", 7, ifd);
304 if (varvalue) { 304 if (varvalue) {
@@ -1159,12 +1159,12 @@ static char *run_mapping(char *physical, struct mapping_defn_t *map)
1159 1159
1160static llist_t *find_iface_state(llist_t *state_list, const char *iface) 1160static llist_t *find_iface_state(llist_t *state_list, const char *iface)
1161{ 1161{
1162 unsigned iface_len = strlen(iface);
1163 llist_t *search = state_list; 1162 llist_t *search = state_list;
1164 1163
1165 while (search) { 1164 while (search) {
1166 if ((strncmp(search->data, iface, iface_len) == 0) 1165 char *after_iface = is_prefixed_with(search->data, iface);
1167 && (search->data[iface_len] == '=') 1166 if (after_iface
1167 && *after_iface == '='
1168 ) { 1168 ) {
1169 return search; 1169 return search;
1170 } 1170 }
diff --git a/networking/inetd.c b/networking/inetd.c
index 8148925ce..dce5a0885 100644
--- a/networking/inetd.c
+++ b/networking/inetd.c
@@ -727,7 +727,7 @@ static NOINLINE servtab_t *parse_one_line(void)
727 goto parse_err; 727 goto parse_err;
728#endif 728#endif
729 } 729 }
730 if (strncmp(arg, "rpc/", 4) == 0) { 730 if (is_prefixed_with(arg, "rpc/")) {
731#if ENABLE_FEATURE_INETD_RPC 731#if ENABLE_FEATURE_INETD_RPC
732 unsigned n; 732 unsigned n;
733 arg += 4; 733 arg += 4;
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c
index aa4779ad1..4072d0626 100644
--- a/networking/libiproute/ipaddress.c
+++ b/networking/libiproute/ipaddress.c
@@ -701,7 +701,7 @@ static int ipaddr_modify(int cmd, char **argv)
701 /* There was no "dev IFACE", but we need that */ 701 /* There was no "dev IFACE", but we need that */
702 bb_error_msg_and_die("need \"dev IFACE\""); 702 bb_error_msg_and_die("need \"dev IFACE\"");
703 } 703 }
704 if (l && strncmp(d, l, strlen(d)) != 0) { 704 if (l && !is_prefixed_with(l, d)) {
705 bb_error_msg_and_die("\"dev\" (%s) must match \"label\" (%s)", d, l); 705 bb_error_msg_and_die("\"dev\" (%s) must match \"label\" (%s)", d, l);
706 } 706 }
707 707
diff --git a/networking/nameif.c b/networking/nameif.c
index 9a8846dc0..9b18a6d16 100644
--- a/networking/nameif.c
+++ b/networking/nameif.c
@@ -161,19 +161,19 @@ static void nameif_parse_selector(ethtable_t *ch, char *selector)
161 if (*next) 161 if (*next)
162 *next++ = '\0'; 162 *next++ = '\0';
163 /* Check for selectors, mac= is assumed */ 163 /* Check for selectors, mac= is assumed */
164 if (strncmp(selector, "bus=", 4) == 0) { 164 if (is_prefixed_with(selector, "bus=")) {
165 ch->bus_info = xstrdup(selector + 4); 165 ch->bus_info = xstrdup(selector + 4);
166 found_selector++; 166 found_selector++;
167 } else if (strncmp(selector, "driver=", 7) == 0) { 167 } else if (is_prefixed_with(selector, "driver=")) {
168 ch->driver = xstrdup(selector + 7); 168 ch->driver = xstrdup(selector + 7);
169 found_selector++; 169 found_selector++;
170 } else if (strncmp(selector, "phyaddr=", 8) == 0) { 170 } else if (is_prefixed_with(selector, "phyaddr=")) {
171 ch->phy_address = xatoi_positive(selector + 8); 171 ch->phy_address = xatoi_positive(selector + 8);
172 found_selector++; 172 found_selector++;
173 } else { 173 } else {
174#endif 174#endif
175 lmac = xmalloc(ETH_ALEN); 175 lmac = xmalloc(ETH_ALEN);
176 ch->mac = ether_aton_r(selector + (strncmp(selector, "mac=", 4) != 0 ? 0 : 4), lmac); 176 ch->mac = ether_aton_r(selector + (is_prefixed_with(selector, "mac=") ? 4 : 0), lmac);
177 if (ch->mac == NULL) 177 if (ch->mac == NULL)
178 bb_error_msg_and_die("can't parse %s", selector); 178 bb_error_msg_and_die("can't parse %s", selector);
179#if ENABLE_FEATURE_NAMEIF_EXTENDED 179#if ENABLE_FEATURE_NAMEIF_EXTENDED
diff --git a/networking/netstat.c b/networking/netstat.c
index f80b845bc..02f4cc7cc 100644
--- a/networking/netstat.c
+++ b/networking/netstat.c
@@ -228,12 +228,12 @@ static long extract_socket_inode(const char *lname)
228{ 228{
229 long inode = -1; 229 long inode = -1;
230 230
231 if (strncmp(lname, "socket:[", sizeof("socket:[")-1) == 0) { 231 if (is_prefixed_with(lname, "socket:[")) {
232 /* "socket:[12345]", extract the "12345" as inode */ 232 /* "socket:[12345]", extract the "12345" as inode */
233 inode = bb_strtoul(lname + sizeof("socket:[")-1, (char**)&lname, 0); 233 inode = bb_strtoul(lname + sizeof("socket:[")-1, (char**)&lname, 0);
234 if (*lname != ']') 234 if (*lname != ']')
235 inode = -1; 235 inode = -1;
236 } else if (strncmp(lname, "[0000]:", sizeof("[0000]:")-1) == 0) { 236 } else if (is_prefixed_with(lname, "[0000]:")) {
237 /* "[0000]:12345", extract the "12345" as inode */ 237 /* "[0000]:12345", extract the "12345" as inode */
238 inode = bb_strtoul(lname + sizeof("[0000]:")-1, NULL, 0); 238 inode = bb_strtoul(lname + sizeof("[0000]:")-1, NULL, 0);
239 if (errno) /* not NUL terminated? */ 239 if (errno) /* not NUL terminated? */
diff --git a/procps/mpstat.c b/procps/mpstat.c
index af3263d67..6028903fa 100644
--- a/procps/mpstat.c
+++ b/procps/mpstat.c
@@ -526,7 +526,7 @@ static void get_irqs_from_stat(struct stats_irq *irq)
526 526
527 while (fgets(buf, sizeof(buf), fp)) { 527 while (fgets(buf, sizeof(buf), fp)) {
528 //bb_error_msg("/proc/stat:'%s'", buf); 528 //bb_error_msg("/proc/stat:'%s'", buf);
529 if (strncmp(buf, "intr ", 5) == 0) { 529 if (is_prefixed_with(buf, "intr ")) {
530 /* Read total number of IRQs since system boot */ 530 /* Read total number of IRQs since system boot */
531 sscanf(buf + 5, "%"FMT_DATA"u", &irq->irq_nr); 531 sscanf(buf + 5, "%"FMT_DATA"u", &irq->irq_nr);
532 } 532 }
diff --git a/procps/powertop.c b/procps/powertop.c
index ddda5bd93..18affacdd 100644
--- a/procps/powertop.c
+++ b/procps/powertop.c
@@ -458,9 +458,9 @@ static NOINLINE int process_timer_stats(void)
458 // func = "Load balancing tick"; 458 // func = "Load balancing tick";
459 //} 459 //}
460 460
461 if (strncmp(func, "tick_nohz_", 10) == 0) 461 if (is_prefixed_with(func, "tick_nohz_"))
462 continue; 462 continue;
463 if (strncmp(func, "tick_setup_sched_timer", 20) == 0) 463 if (is_prefixed_with(func, "tick_setup_sched_timer"))
464 continue; 464 continue;
465 //if (strcmp(process, "powertop") == 0) 465 //if (strcmp(process, "powertop") == 0)
466 // continue; 466 // continue;
diff --git a/procps/pwdx.c b/procps/pwdx.c
index 22b892275..4e34149ed 100644
--- a/procps/pwdx.c
+++ b/procps/pwdx.c
@@ -41,7 +41,7 @@ int pwdx_main(int argc UNUSED_PARAM, char **argv)
41 // Allowed on the command line: 41 // Allowed on the command line:
42 // /proc/NUM 42 // /proc/NUM
43 // NUM 43 // NUM
44 if (strncmp(arg, "/proc/", 6) == 0) 44 if (is_prefixed_with(arg, "/proc/"))
45 arg += 6; 45 arg += 6;
46 46
47 pid = bb_strtou(arg, NULL, 10); 47 pid = bb_strtou(arg, NULL, 10);
diff --git a/shell/hush.c b/shell/hush.c
index 92d790180..f2c0a70f2 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -5884,7 +5884,7 @@ static FILE *generate_stream_from_string(const char *s, pid_t *pid_p)
5884 * Our solution: ONLY bare $(trap) or `trap` is special. 5884 * Our solution: ONLY bare $(trap) or `trap` is special.
5885 */ 5885 */
5886 s = skip_whitespace(s); 5886 s = skip_whitespace(s);
5887 if (strncmp(s, "trap", 4) == 0 5887 if (is_prefixed_with(s, "trap")
5888 && skip_whitespace(s + 4)[0] == '\0' 5888 && skip_whitespace(s + 4)[0] == '\0'
5889 ) { 5889 ) {
5890 static const char *const argv[] = { NULL, NULL }; 5890 static const char *const argv[] = { NULL, NULL };
diff --git a/util-linux/acpid.c b/util-linux/acpid.c
index fc8151f6a..0f2cb6bdc 100644
--- a/util-linux/acpid.c
+++ b/util-linux/acpid.c
@@ -151,7 +151,7 @@ static const char *find_action(struct input_event *ev, const char *buf)
151 } 151 }
152 152
153 if (buf) { 153 if (buf) {
154 if (strncmp(buf, evt_tab[i].desc, strlen(buf)) == 0) { 154 if (is_prefixed_with(evt_tab[i].desc, buf)) {
155 action = evt_tab[i].desc; 155 action = evt_tab[i].desc;
156 break; 156 break;
157 } 157 }
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c
index 39eb27b47..7fe70fb72 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -2781,14 +2781,14 @@ is_ide_cdrom_or_tape(const char *device)
2781 the process hangs on the attempt to read a music CD. 2781 the process hangs on the attempt to read a music CD.
2782 So try to be careful. This only works since 2.1.73. */ 2782 So try to be careful. This only works since 2.1.73. */
2783 2783
2784 if (strncmp("/dev/hd", device, 7)) 2784 if (!is_prefixed_with(device, "/dev/hd"))
2785 return 0; 2785 return 0;
2786 2786
2787 snprintf(buf, sizeof(buf), "/proc/ide/%s/media", device+5); 2787 snprintf(buf, sizeof(buf), "/proc/ide/%s/media", device+5);
2788 procf = fopen_for_read(buf); 2788 procf = fopen_for_read(buf);
2789 if (procf != NULL && fgets(buf, sizeof(buf), procf)) 2789 if (procf != NULL && fgets(buf, sizeof(buf), procf))
2790 is_ide = (!strncmp(buf, "cdrom", 5) || 2790 is_ide = (is_prefixed_with(buf, "cdrom") ||
2791 !strncmp(buf, "tape", 4)); 2791 is_prefixed_with(buf, "tape"));
2792 else 2792 else
2793 /* Now when this proc file does not exist, skip the 2793 /* Now when this proc file does not exist, skip the
2794 device when it is read-only. */ 2794 device when it is read-only. */
diff --git a/util-linux/fdisk_osf.c b/util-linux/fdisk_osf.c
index ff16389bd..af04cfcc8 100644
--- a/util-linux/fdisk_osf.c
+++ b/util-linux/fdisk_osf.c
@@ -854,7 +854,7 @@ xbsd_initlabel(struct partition *p)
854 854
855 d->d_magic = BSD_DISKMAGIC; 855 d->d_magic = BSD_DISKMAGIC;
856 856
857 if (strncmp(disk_device, "/dev/sd", 7) == 0) 857 if (is_prefixed_with(disk_device, "/dev/sd"))
858 d->d_type = BSD_DTYPE_SCSI; 858 d->d_type = BSD_DTYPE_SCSI;
859 else 859 else
860 d->d_type = BSD_DTYPE_ST506; 860 d->d_type = BSD_DTYPE_ST506;
diff --git a/util-linux/fdisk_sgi.c b/util-linux/fdisk_sgi.c
index 785fc661b..23ebc56ef 100644
--- a/util-linux/fdisk_sgi.c
+++ b/util-linux/fdisk_sgi.c
@@ -440,7 +440,7 @@ sgi_write_table(void)
440 (unsigned int*)sgilabel, sizeof(*sgilabel)) == 0); 440 (unsigned int*)sgilabel, sizeof(*sgilabel)) == 0);
441 441
442 write_sector(0, sgilabel); 442 write_sector(0, sgilabel);
443 if (!strncmp((char*)sgilabel->directory[0].vol_file_name, "sgilabel", 8)) { 443 if (is_prefixed_with((char*)sgilabel->directory[0].vol_file_name, "sgilabel")) {
444 /* 444 /*
445 * keep this habit of first writing the "sgilabel". 445 * keep this habit of first writing the "sgilabel".
446 * I never tested whether it works without (AN 981002). 446 * I never tested whether it works without (AN 981002).
diff --git a/util-linux/findfs.c b/util-linux/findfs.c
index 49e8979ac..07734f359 100644
--- a/util-linux/findfs.c
+++ b/util-linux/findfs.c
@@ -27,7 +27,7 @@ int findfs_main(int argc UNUSED_PARAM, char **argv)
27 if (!dev) 27 if (!dev)
28 bb_show_usage(); 28 bb_show_usage();
29 29
30 if (strncmp(dev, "/dev/", 5) == 0) { 30 if (is_prefixed_with(dev, "/dev/")) {
31 /* Just pass any /dev/xxx name right through. 31 /* Just pass any /dev/xxx name right through.
32 * This might aid in some scripts being able 32 * This might aid in some scripts being able
33 * to call this unconditionally */ 33 * to call this unconditionally */
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index b2d56575f..ccc00d365 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -610,7 +610,7 @@ static void make_device(char *device_name, char *path, int operation)
610 * We use strstr("/block/") to forestall future surprises. 610 * We use strstr("/block/") to forestall future surprises.
611 */ 611 */
612 type = S_IFCHR; 612 type = S_IFCHR;
613 if (strstr(path, "/block/") || (G.subsystem && strncmp(G.subsystem, "block", 5) == 0)) 613 if (strstr(path, "/block/") || (G.subsystem && is_prefixed_with(G.subsystem, "block")))
614 type = S_IFBLK; 614 type = S_IFBLK;
615 615
616#if ENABLE_FEATURE_MDEV_CONF 616#if ENABLE_FEATURE_MDEV_CONF
diff --git a/util-linux/mount.c b/util-linux/mount.c
index fbc89c862..cb40c802d 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -641,7 +641,7 @@ static llist_t *get_block_backed_filesystems(void)
641 if (!f) continue; 641 if (!f) continue;
642 642
643 while ((buf = xmalloc_fgetline(f)) != NULL) { 643 while ((buf = xmalloc_fgetline(f)) != NULL) {
644 if (strncmp(buf, "nodev", 5) == 0 && isspace(buf[5])) 644 if (is_prefixed_with(buf, "nodev") && isspace(buf[5]))
645 goto next; 645 goto next;
646 fs = skip_whitespace(buf); 646 fs = skip_whitespace(buf);
647 if (*fs == '#' || *fs == '*' || !*fs) 647 if (*fs == '#' || *fs == '*' || !*fs)
@@ -1364,9 +1364,9 @@ static NOINLINE int nfsmount(struct mntent *mp, unsigned long vfsflags, char *fi
1364 strcspn(opteq, " \t\n\r,")); 1364 strcspn(opteq, " \t\n\r,"));
1365 continue; 1365 continue;
1366 case 18: // "proto" 1366 case 18: // "proto"
1367 if (!strncmp(opteq, "tcp", 3)) 1367 if (is_prefixed_with(opteq, "tcp"))
1368 tcp = 1; 1368 tcp = 1;
1369 else if (!strncmp(opteq, "udp", 3)) 1369 else if (is_prefixed_with(opteq, "udp"))
1370 tcp = 0; 1370 tcp = 0;
1371 else 1371 else
1372 bb_error_msg("warning: unrecognized proto= option"); 1372 bb_error_msg("warning: unrecognized proto= option");
@@ -1459,7 +1459,7 @@ static NOINLINE int nfsmount(struct mntent *mp, unsigned long vfsflags, char *fi
1459 "rdirplus\0" 1459 "rdirplus\0"
1460 "acl\0"; 1460 "acl\0";
1461 int val = 1; 1461 int val = 1;
1462 if (!strncmp(opt, "no", 2)) { 1462 if (is_prefixed_with(opt, "no")) {
1463 val = 0; 1463 val = 0;
1464 opt += 2; 1464 opt += 2;
1465 } 1465 }
@@ -1979,7 +1979,7 @@ static int singlemount(struct mntent *mp, int ignore_busy)
1979 } 1979 }
1980 1980
1981 // Might this be an NFS filesystem? 1981 // Might this be an NFS filesystem?
1982 if ((!mp->mnt_type || strncmp(mp->mnt_type, "nfs", 3) == 0) 1982 if ((!mp->mnt_type || is_prefixed_with(mp->mnt_type, "nfs"))
1983 && strchr(mp->mnt_fsname, ':') != NULL 1983 && strchr(mp->mnt_fsname, ':') != NULL
1984 ) { 1984 ) {
1985 if (!mp->mnt_type) 1985 if (!mp->mnt_type)
diff --git a/util-linux/rtcwake.c b/util-linux/rtcwake.c
index 53d9384db..8aee0cfcb 100644
--- a/util-linux/rtcwake.c
+++ b/util-linux/rtcwake.c
@@ -66,7 +66,7 @@ static NOINLINE bool may_wakeup(const char *rtcname)
66 return false; 66 return false;
67 67
68 /* wakeup events could be disabled or not supported */ 68 /* wakeup events could be disabled or not supported */
69 return strncmp(buf, "enabled\n", 8) == 0; 69 return is_prefixed_with(buf, "enabled\n") != NULL;
70} 70}
71 71
72static NOINLINE void setup_alarm(int fd, time_t *wakeup, time_t rtc_time) 72static NOINLINE void setup_alarm(int fd, time_t *wakeup, time_t rtc_time)
diff --git a/util-linux/volume_id/get_devname.c b/util-linux/volume_id/get_devname.c
index 0c6bdfddf..53bdbdf09 100644
--- a/util-linux/volume_id/get_devname.c
+++ b/util-linux/volume_id/get_devname.c
@@ -302,9 +302,9 @@ int resolve_mount_spec(char **fsname)
302{ 302{
303 char *tmp = *fsname; 303 char *tmp = *fsname;
304 304
305 if (strncmp(*fsname, "UUID=", 5) == 0) 305 if (is_prefixed_with(*fsname, "UUID="))
306 tmp = get_devname_from_uuid(*fsname + 5); 306 tmp = get_devname_from_uuid(*fsname + 5);
307 else if (strncmp(*fsname, "LABEL=", 6) == 0) 307 else if (is_prefixed_with(*fsname, "LABEL=") == 0)
308 tmp = get_devname_from_label(*fsname + 6); 308 tmp = get_devname_from_label(*fsname + 6);
309 309
310 if (tmp == *fsname) 310 if (tmp == *fsname)