mirror of
https://github.com/systemd/systemd.git
synced 2024-12-23 21:35:11 +03:00
use strneq instead of strncmp
This commit is contained in:
parent
8d61671016
commit
641906e936
@ -459,7 +459,7 @@ int config_parse_exec(
|
||||
|
||||
k = 0;
|
||||
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
|
||||
if (strncmp(w, ";", MAX(l, 1U)) == 0)
|
||||
if (strneq(w, ";", MAX(l, 1U)))
|
||||
break;
|
||||
|
||||
k++;
|
||||
@ -471,9 +471,9 @@ int config_parse_exec(
|
||||
|
||||
k = 0;
|
||||
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
|
||||
if (strncmp(w, ";", MAX(l, 1U)) == 0)
|
||||
if (strneq(w, ";", MAX(l, 1U)))
|
||||
break;
|
||||
else if (strncmp(w, "\\;", MAX(l, 1U)) == 0)
|
||||
else if (strneq(w, "\\;", MAX(l, 1U)))
|
||||
w ++;
|
||||
|
||||
if (honour_argv0 && w == rvalue) {
|
||||
@ -2670,7 +2670,7 @@ void unit_dump_config_items(FILE *f) {
|
||||
prefix_len = dot-i;
|
||||
|
||||
if (dot)
|
||||
if (!prev || strncmp(prev, i, prefix_len+1) != 0) {
|
||||
if (!prev || !strneq(prev, i, prefix_len+1)) {
|
||||
if (prev)
|
||||
fputc('\n', f);
|
||||
|
||||
|
@ -312,17 +312,17 @@ static int parse_flags(const char *flag_str, int flags) {
|
||||
size_t l;
|
||||
|
||||
FOREACH_WORD(w, l, flag_str, state) {
|
||||
if (strncmp("masked", w, l) == 0)
|
||||
if (strneq("masked", w, l))
|
||||
flags |= SHOW_MASKED;
|
||||
else if (strncmp ("equivalent", w, l) == 0)
|
||||
else if (strneq ("equivalent", w, l))
|
||||
flags |= SHOW_EQUIVALENT;
|
||||
else if (strncmp("redirected", w, l) == 0)
|
||||
else if (strneq("redirected", w, l))
|
||||
flags |= SHOW_REDIRECTED;
|
||||
else if (strncmp("overridden", w, l) == 0)
|
||||
else if (strneq("overridden", w, l))
|
||||
flags |= SHOW_OVERRIDDEN;
|
||||
else if (strncmp("unchanged", w, l) == 0)
|
||||
else if (strneq("unchanged", w, l))
|
||||
flags |= SHOW_UNCHANGED;
|
||||
else if (strncmp("default", w, l) == 0)
|
||||
else if (strneq("default", w, l))
|
||||
flags |= SHOW_DEFAULTS;
|
||||
else
|
||||
return -EINVAL;
|
||||
|
@ -309,7 +309,7 @@ _public_ struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enume
|
||||
}
|
||||
|
||||
if (move_later &&
|
||||
strncmp(entry->syspath, move_later->syspath, move_later_prefix) != 0) {
|
||||
!strneq(entry->syspath, move_later->syspath, move_later_prefix)) {
|
||||
|
||||
udev_list_entry_add(&udev_enumerate->devices_list, move_later->syspath, NULL);
|
||||
move_later = NULL;
|
||||
|
@ -854,7 +854,7 @@ static int convert_x11_to_vconsole(DBusConnection *connection) {
|
||||
* layout stripped off. */
|
||||
if (x > 0 &&
|
||||
strlen(a[1]) == x &&
|
||||
strncmp(state.x11_layout, a[1], x) == 0)
|
||||
strneq(state.x11_layout, a[1], x))
|
||||
matching = 5;
|
||||
else {
|
||||
size_t w;
|
||||
|
@ -439,19 +439,19 @@ InhibitWhat inhibit_what_from_string(const char *s) {
|
||||
size_t l;
|
||||
|
||||
FOREACH_WORD_SEPARATOR(w, l, s, ":", state) {
|
||||
if (l == 8 && strncmp(w, "shutdown", l) == 0)
|
||||
if (l == 8 && strneq(w, "shutdown", l))
|
||||
what |= INHIBIT_SHUTDOWN;
|
||||
else if (l == 5 && strncmp(w, "sleep", l) == 0)
|
||||
else if (l == 5 && strneq(w, "sleep", l))
|
||||
what |= INHIBIT_SLEEP;
|
||||
else if (l == 4 && strncmp(w, "idle", l) == 0)
|
||||
else if (l == 4 && strneq(w, "idle", l))
|
||||
what |= INHIBIT_IDLE;
|
||||
else if (l == 16 && strncmp(w, "handle-power-key", l) == 0)
|
||||
else if (l == 16 && strneq(w, "handle-power-key", l))
|
||||
what |= INHIBIT_HANDLE_POWER_KEY;
|
||||
else if (l == 18 && strncmp(w, "handle-suspend-key", l) == 0)
|
||||
else if (l == 18 && strneq(w, "handle-suspend-key", l))
|
||||
what |= INHIBIT_HANDLE_SUSPEND_KEY;
|
||||
else if (l == 20 && strncmp(w, "handle-hibernate-key", l) == 0)
|
||||
else if (l == 20 && strneq(w, "handle-hibernate-key", l))
|
||||
what |= INHIBIT_HANDLE_HIBERNATE_KEY;
|
||||
else if (l == 17 && strncmp(w, "handle-lid-switch", l) == 0)
|
||||
else if (l == 17 && strneq(w, "handle-lid-switch", l))
|
||||
what |= INHIBIT_HANDLE_LID_SWITCH;
|
||||
else
|
||||
return _INHIBIT_WHAT_INVALID;
|
||||
|
@ -196,7 +196,7 @@ _public_ int sd_uid_is_on_seat(uid_t uid, int require_active, const char *seat)
|
||||
}
|
||||
|
||||
FOREACH_WORD(w, l, s, state) {
|
||||
if (strncmp(t, w, l) == 0) {
|
||||
if (strneq(t, w, l)) {
|
||||
free(s);
|
||||
free(t);
|
||||
|
||||
|
@ -811,7 +811,7 @@ int cg_get_by_pid(const char *controller, pid_t pid, char **path) {
|
||||
continue;
|
||||
|
||||
l++;
|
||||
if (strncmp(l, controller, cs) != 0)
|
||||
if (!strneq(l, controller, cs))
|
||||
continue;
|
||||
|
||||
if (l[cs] != ':')
|
||||
|
@ -128,7 +128,7 @@ bool strv_env_is_valid(char **e) {
|
||||
/* Check if there are duplicate assginments */
|
||||
k = strcspn(*p, "=");
|
||||
STRV_FOREACH(q, p + 1)
|
||||
if (strncmp(*p, *q, k) == 0 && (*q)[k] == '=')
|
||||
if (strneq(*p, *q, k) && (*q)[k] == '=')
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -171,7 +171,7 @@ static int env_append(char **r, char ***k, char **a) {
|
||||
n++;
|
||||
|
||||
for (j = r; j < *k; j++)
|
||||
if (strncmp(*j, *a, n) == 0)
|
||||
if (strneq(*j, *a, n))
|
||||
break;
|
||||
|
||||
if (j >= *k)
|
||||
@ -247,7 +247,7 @@ static bool env_match(const char *t, const char *pattern) {
|
||||
if (!strchr(pattern, '=')) {
|
||||
size_t l = strlen(pattern);
|
||||
|
||||
return strncmp(t, pattern, l) == 0 && t[l] == '=';
|
||||
return strneq(t, pattern, l) && t[l] == '=';
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -363,7 +363,7 @@ char *strv_env_get_n(char **l, const char *name, size_t k) {
|
||||
return NULL;
|
||||
|
||||
STRV_FOREACH(i, l)
|
||||
if (strncmp(*i, name, k) == 0 &&
|
||||
if (strneq(*i, name, k) &&
|
||||
(*i)[k] == '=')
|
||||
return *i + k + 1;
|
||||
|
||||
@ -391,7 +391,7 @@ char **strv_env_clean(char **e) {
|
||||
|
||||
n = strcspn(*p, "=");
|
||||
STRV_FOREACH(q, p + 1)
|
||||
if (strncmp(*p, *q, n) == 0 && (*q)[n] == '=') {
|
||||
if (strneq(*p, *q, n) && (*q)[n] == '=') {
|
||||
duplicate = true;
|
||||
break;
|
||||
}
|
||||
|
@ -432,7 +432,7 @@ bool socket_address_equal(const SocketAddress *a, const SocketAddress *b) {
|
||||
return false;
|
||||
|
||||
if (a->sockaddr.un.sun_path[0]) {
|
||||
if (strncmp(a->sockaddr.un.sun_path, b->sockaddr.un.sun_path, sizeof(a->sockaddr.un.sun_path)) != 0)
|
||||
if (!strneq(a->sockaddr.un.sun_path, b->sockaddr.un.sun_path, sizeof(a->sockaddr.un.sun_path)))
|
||||
return false;
|
||||
} else {
|
||||
if (memcmp(a->sockaddr.un.sun_path, b->sockaddr.un.sun_path, a->size) != 0)
|
||||
|
@ -720,7 +720,7 @@ int parse_env_file(
|
||||
value = va_arg(ap, char **);
|
||||
|
||||
n = strlen(key);
|
||||
if (strncmp(p, key, n) != 0 ||
|
||||
if (!strneq(p, key, n) ||
|
||||
p[n] != '=')
|
||||
continue;
|
||||
|
||||
|
@ -69,16 +69,16 @@ static size_t patch_in_line(char *line, size_t l, size_t left) {
|
||||
} else
|
||||
r = 0;
|
||||
|
||||
if (l == 5 && strncmp(line, "BEGIN", 5) == 0) {
|
||||
if (l == 5 && strneq(line, "BEGIN", 5)) {
|
||||
r += l;
|
||||
auth_over = true;
|
||||
|
||||
} else if (l == 17 && strncmp(line, "NEGOTIATE_UNIX_FD", 17) == 0) {
|
||||
} else if (l == 17 && strneq(line, "NEGOTIATE_UNIX_FD", 17)) {
|
||||
memmove(line + 13, line + 17, left);
|
||||
memcpy(line, "NEGOTIATE_NOP", 13);
|
||||
r += 13;
|
||||
|
||||
} else if (l >= 14 && strncmp(line, "AUTH EXTERNAL ", 14) == 0) {
|
||||
} else if (l >= 14 && strneq(line, "AUTH EXTERNAL ", 14)) {
|
||||
char uid[20*2 + 1];
|
||||
size_t len;
|
||||
|
||||
|
@ -267,10 +267,10 @@ static int get_file_options(struct udev *udev,
|
||||
if (vendor == NULL) {
|
||||
if (vendor_in == NULL)
|
||||
break;
|
||||
} else if ((vendor_in && strncmp(vendor, vendor_in,
|
||||
strlen(vendor_in)) == 0) &&
|
||||
(!model_in || (strncmp(model, model_in,
|
||||
strlen(model_in)) == 0))) {
|
||||
} else if ((vendor_in && strneq(vendor, vendor_in,
|
||||
strlen(vendor_in))) &&
|
||||
(!model_in || (strneq(model, model_in,
|
||||
strlen(model_in))))) {
|
||||
/*
|
||||
* Matched vendor and optionally model.
|
||||
*
|
||||
|
@ -436,7 +436,7 @@ static int do_scsi_page0_inquiry(struct udev *udev,
|
||||
* If the vendor id appears in the page assume the page is
|
||||
* invalid.
|
||||
*/
|
||||
if (!strncmp((char *)&buffer[VENDOR_LENGTH], dev_scsi->vendor, VENDOR_LENGTH)) {
|
||||
if (strneq((char *)&buffer[VENDOR_LENGTH], dev_scsi->vendor, VENDOR_LENGTH)) {
|
||||
log_debug("%s: invalid page0 data\n", dev_scsi->kernel);
|
||||
return 1;
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ static int dev_pci_slot(struct udev_device *dev, struct netnames *names) {
|
||||
snprintf(str, sizeof(str), "%s/%s/address", slots, dent->d_name);
|
||||
if (read_one_line_file(str, &address) >= 0) {
|
||||
/* match slot address with device by stripping the function */
|
||||
if (strncmp(address, udev_device_get_sysname(names->pcidev), strlen(address)) == 0)
|
||||
if (strneq(address, udev_device_get_sysname(names->pcidev), strlen(address)))
|
||||
hotplug_slot = i;
|
||||
free(address);
|
||||
}
|
||||
|
@ -1737,7 +1737,7 @@ static int match_key(struct udev_rules *rules, struct token *token, const char *
|
||||
if (next != NULL) {
|
||||
size_t matchlen = (size_t)(next - s);
|
||||
|
||||
match = (matchlen == len && strncmp(s, val, matchlen) == 0);
|
||||
match = (matchlen == len && strneq(s, val, matchlen));
|
||||
if (match)
|
||||
break;
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user