}
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");
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);
* 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);
/* 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)
) {
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;
cp++;
continue;
}
- if (strncmp(cp, "/../"+1, 3) == 0) {
+ if (is_prefixed_with(cp, "/../"+1)) {
cp += 3;
continue;
}
*/
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);
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 */
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 {
}
/* 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]))
#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;
* 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
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;
#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;
}
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;
}
// 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;
// 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;
/* 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;
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". */
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);
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));
}
#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++;
}
#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)
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;
}
}
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));
}
}
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);
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);
}
}
}
int FAST_FUNC match_fstype(const struct mntent *mt, const char *t_fstype)
{
int match = 1;
- int len;
if (!t_fstype)
return match;
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;
}
// 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; \
}
// 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;
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; \
}
char buffer[128];
while (fgets(buffer, sizeof(buffer), f)) {
- if (strncmp(buffer, "UTC", 3) == 0) {
+ if (is_prefixed_with(buffer, "UTC")) {
utc = 1;
break;
}
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;
}
char *fnamesfx;
char *sfx_char;
char *name_colon;
- unsigned user_len;
int old_fd;
int new_fd;
int i;
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+");
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];
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) {
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));
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;
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;
}
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 ,
};
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;
}
}
// 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;
}
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,
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);
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 {
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;
}
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
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;
*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;
"firmware",
};
size_t len;
- int j, length;
+ int j;
char *ptr, *the_module;
const char *field = env->field;
int tags = env->tags;
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);
}
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);
}
// TODO: open only once, invent config_rewind()
static int already_loaded(const char *name)
{
- int ret, namelen;
+ int ret;
char *line;
FILE *fp;
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;
}
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;
}
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);
* 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;
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);
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;
{
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;
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) {
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);
/* "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
# 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) {
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;
}
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;
/* 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);
}
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
{
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? */
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);
}
// 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;
// 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);
* 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 };
}
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;
}
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. */
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;
(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).
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 */
* 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
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)
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");
"rdirplus\0"
"acl\0";
int val = 1;
- if (!strncmp(opt, "no", 2)) {
+ if (is_prefixed_with(opt, "no")) {
val = 0;
opt += 2;
}
}
// 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)
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)
{
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)