chiark / gitweb /
use strneq instead of strncmp
authorThomas Hindoe Paaboel Andersen <phomes@gmail.com>
Tue, 12 Feb 2013 20:47:36 +0000 (21:47 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 12 Feb 2013 23:56:13 +0000 (00:56 +0100)
15 files changed:
src/core/load-fragment.c
src/delta/delta.c
src/libudev/libudev-enumerate.c
src/locale/localed.c
src/login/logind-inhibit.c
src/login/sd-login.c
src/shared/cgroup-util.c
src/shared/env-util.c
src/shared/socket-util.c
src/shared/util.c
src/stdio-bridge/stdio-bridge.c
src/udev/scsi_id/scsi_id.c
src/udev/scsi_id/scsi_serial.c
src/udev/udev-builtin-net_id.c
src/udev/udev-rules.c

index 44698d4..6e333aa 100644 (file)
@@ -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);
 
index 9f20938..16b1002 100644 (file)
@@ -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;
index 2c1f7ab..5ccaabd 100644 (file)
@@ -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;
index 6b1a793..fedcdfb 100644 (file)
@@ -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;
index f1b9cca..2c1a412 100644 (file)
@@ -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;
index 4bc51e7..b81dddf 100644 (file)
@@ -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);
 
index acace52..7efbc2e 100644 (file)
@@ -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] != ':')
index 9a833d2..0f1ac92 100644 (file)
@@ -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;
                         }
index 56ec99f..39b6142 100644 (file)
@@ -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)
index 24f9e7e..8dceb82 100644 (file)
@@ -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;
 
index f926fe5..adc692f 100644 (file)
@@ -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;
 
index fa0413c..d664787 100644 (file)
@@ -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.
                                  *
index 950b8ad..d522a23 100644 (file)
@@ -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;
                 }
index 7ffdaad..c55c34d 100644 (file)
@@ -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);
                 }
index a86f8c3..d2810a0 100644 (file)
@@ -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 {