[systemd-commits] 2 commits - src/core src/delta src/libudev src/locale src/login src/shared src/stdio-bridge src/udev

Lennart Poettering lennart at kemper.freedesktop.org
Tue Feb 12 15:56:19 PST 2013


 src/core/load-fragment.c        |    8 ++++----
 src/delta/delta.c               |   12 ++++++------
 src/libudev/libudev-enumerate.c |    2 +-
 src/locale/localed.c            |    2 +-
 src/login/logind-inhibit.c      |   14 +++++++-------
 src/login/sd-login.c            |    2 +-
 src/shared/calendarspec.c       |    8 ++++----
 src/shared/cgroup-util.c        |    2 +-
 src/shared/env-util.c           |   10 +++++-----
 src/shared/socket-util.c        |    2 +-
 src/shared/util.c               |    6 +++---
 src/shared/util.h               |    2 ++
 src/stdio-bridge/stdio-bridge.c |    6 +++---
 src/udev/scsi_id/scsi_id.c      |   14 +++++++-------
 src/udev/scsi_id/scsi_serial.c  |    2 +-
 src/udev/udev-builtin-net_id.c  |    2 +-
 src/udev/udev-rules.c           |    2 +-
 17 files changed, 49 insertions(+), 47 deletions(-)

New commits:
commit b43d1d01eabe2cbbf393e8f56b76e182c6069c4c
Author: Thomas Hindoe Paaboel Andersen <phomes at gmail.com>
Date:   Tue Feb 12 21:47:37 2013 +0100

    util: introduce strcaseeq/strncaseeq

diff --git a/src/shared/calendarspec.c b/src/shared/calendarspec.c
index c2eae3f..cc68077 100644
--- a/src/shared/calendarspec.c
+++ b/src/shared/calendarspec.c
@@ -653,7 +653,7 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) {
         if (!c)
                 return -ENOMEM;
 
-        if (strcasecmp(p, "hourly") == 0) {
+        if (strcaseeq(p, "hourly")) {
                 r = const_chain(0, &c->minute);
                 if (r < 0)
                         goto fail;
@@ -661,7 +661,7 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) {
                 if (r < 0)
                         goto fail;
 
-        } else if (strcasecmp(p, "daily") == 0) {
+        } else if (strcaseeq(p, "daily")) {
                 r = const_chain(0, &c->hour);
                 if (r < 0)
                         goto fail;
@@ -672,7 +672,7 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) {
                 if (r < 0)
                         goto fail;
 
-        } else if (strcasecmp(p, "monthly") == 0) {
+        } else if (strcaseeq(p, "monthly")) {
                 r = const_chain(1, &c->day);
                 if (r < 0)
                         goto fail;
@@ -686,7 +686,7 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) {
                 if (r < 0)
                         goto fail;
 
-        } else if (strcasecmp(p, "weekly") == 0) {
+        } else if (strcaseeq(p, "weekly")) {
 
                 c->weekdays_bits = 1;
 
diff --git a/src/shared/util.c b/src/shared/util.c
index 8dceb82..aa0532a 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -218,9 +218,9 @@ void close_many(const int fds[], unsigned n_fd) {
 int parse_boolean(const char *v) {
         assert(v);
 
-        if (streq(v, "1") || v[0] == 'y' || v[0] == 'Y' || v[0] == 't' || v[0] == 'T' || !strcasecmp(v, "on"))
+        if (streq(v, "1") || v[0] == 'y' || v[0] == 'Y' || v[0] == 't' || v[0] == 'T' || strcaseeq(v, "on"))
                 return 1;
-        else if (streq(v, "0") || v[0] == 'n' || v[0] == 'N' || v[0] == 'f' || v[0] == 'F' || !strcasecmp(v, "off"))
+        else if (streq(v, "0") || v[0] == 'n' || v[0] == 'N' || v[0] == 'f' || v[0] == 'F' || strcaseeq(v, "off"))
                 return 0;
 
         return -EINVAL;
diff --git a/src/shared/util.h b/src/shared/util.h
index cd13457..3ad90dd 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -65,6 +65,8 @@ size_t page_size(void);
 
 #define streq(a,b) (strcmp((a),(b)) == 0)
 #define strneq(a, b, n) (strncmp((a), (b), (n)) == 0)
+#define strcaseeq(a,b) (strcasecmp((a),(b)) == 0)
+#define strncaseeq(a, b, n) (strncasecmp((a), (b), (n)) == 0)
 
 bool streq_ptr(const char *a, const char *b);
 
diff --git a/src/udev/scsi_id/scsi_id.c b/src/udev/scsi_id/scsi_id.c
index d664787..dcf03ee 100644
--- a/src/udev/scsi_id/scsi_id.c
+++ b/src/udev/scsi_id/scsi_id.c
@@ -227,7 +227,7 @@ static int get_file_options(struct udev *udev,
                         continue;
 
                 str1 = strsep(&buf, "=");
-                if (str1 && strcasecmp(str1, "VENDOR") == 0) {
+                if (str1 && strcaseeq(str1, "VENDOR")) {
                         str1 = get_value(&buf);
                         if (!str1) {
                                 retval = log_oom();
@@ -236,7 +236,7 @@ static int get_file_options(struct udev *udev,
                         vendor_in = str1;
 
                         str1 = strsep(&buf, "=");
-                        if (str1 && strcasecmp(str1, "MODEL") == 0) {
+                        if (str1 && strcaseeq(str1, "MODEL")) {
                                 str1 = get_value(&buf);
                                 if (!str1) {
                                         retval = log_oom();
@@ -247,7 +247,7 @@ static int get_file_options(struct udev *udev,
                         }
                 }
 
-                if (str1 && strcasecmp(str1, "OPTIONS") == 0) {
+                if (str1 && strcaseeq(str1, "OPTIONS")) {
                         str1 = get_value(&buf);
                         if (!str1) {
                                 retval = log_oom();

commit 641906e9366891e0ad3e6e38b7396a427678c4cf
Author: Thomas Hindoe Paaboel Andersen <phomes at gmail.com>
Date:   Tue Feb 12 21:47:36 2013 +0100

    use strneq instead of strncmp

diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index 44698d4..6e333aa 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -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);
 
diff --git a/src/delta/delta.c b/src/delta/delta.c
index 9f20938..16b1002 100644
--- a/src/delta/delta.c
+++ b/src/delta/delta.c
@@ -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;
diff --git a/src/libudev/libudev-enumerate.c b/src/libudev/libudev-enumerate.c
index 2c1f7ab..5ccaabd 100644
--- a/src/libudev/libudev-enumerate.c
+++ b/src/libudev/libudev-enumerate.c
@@ -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;
diff --git a/src/locale/localed.c b/src/locale/localed.c
index 6b1a793..fedcdfb 100644
--- a/src/locale/localed.c
+++ b/src/locale/localed.c
@@ -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;
diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c
index f1b9cca..2c1a412 100644
--- a/src/login/logind-inhibit.c
+++ b/src/login/logind-inhibit.c
@@ -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;
diff --git a/src/login/sd-login.c b/src/login/sd-login.c
index 4bc51e7..b81dddf 100644
--- a/src/login/sd-login.c
+++ b/src/login/sd-login.c
@@ -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);
 
diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
index acace52..7efbc2e 100644
--- a/src/shared/cgroup-util.c
+++ b/src/shared/cgroup-util.c
@@ -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] != ':')
diff --git a/src/shared/env-util.c b/src/shared/env-util.c
index 9a833d2..0f1ac92 100644
--- a/src/shared/env-util.c
+++ b/src/shared/env-util.c
@@ -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;
                         }
diff --git a/src/shared/socket-util.c b/src/shared/socket-util.c
index 56ec99f..39b6142 100644
--- a/src/shared/socket-util.c
+++ b/src/shared/socket-util.c
@@ -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)
diff --git a/src/shared/util.c b/src/shared/util.c
index 24f9e7e..8dceb82 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -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;
 
diff --git a/src/stdio-bridge/stdio-bridge.c b/src/stdio-bridge/stdio-bridge.c
index f926fe5..adc692f 100644
--- a/src/stdio-bridge/stdio-bridge.c
+++ b/src/stdio-bridge/stdio-bridge.c
@@ -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;
 
diff --git a/src/udev/scsi_id/scsi_id.c b/src/udev/scsi_id/scsi_id.c
index fa0413c..d664787 100644
--- a/src/udev/scsi_id/scsi_id.c
+++ b/src/udev/scsi_id/scsi_id.c
@@ -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.
                                  *
diff --git a/src/udev/scsi_id/scsi_serial.c b/src/udev/scsi_id/scsi_serial.c
index 950b8ad..d522a23 100644
--- a/src/udev/scsi_id/scsi_serial.c
+++ b/src/udev/scsi_id/scsi_serial.c
@@ -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;
                 }
diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c
index 7ffdaad..c55c34d 100644
--- a/src/udev/udev-builtin-net_id.c
+++ b/src/udev/udev-builtin-net_id.c
@@ -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);
                 }
diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index a86f8c3..d2810a0 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -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 {



More information about the systemd-commits mailing list