chiark / gitweb /
Add hasprefix macro to check prefixes of fixed length
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 21 Jun 2013 02:40:10 +0000 (22:40 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 21 Jun 2013 03:03:58 +0000 (23:03 -0400)
src/journal/journal-send.c
src/journal/journald-native.c
src/libsystemd-bus/bus-match.c
src/shared/logs-show.c
src/shared/macro.h

index da1f89268534aa1e1d638f58dd7cb067f79cd07e..fef66fc29aed0c68a928c180b1fd753198764f2c 100644 (file)
@@ -245,7 +245,7 @@ _public_ int sd_journal_sendv(const struct iovec *iov, int n) {
 
                 have_syslog_identifier = have_syslog_identifier ||
                         (c == (char *) iov[i].iov_base + 17 &&
-                         memcmp(iov[i].iov_base, "SYSLOG_IDENTIFIER", 17) == 0);
+                         hasprefix(iov[i].iov_base, "SYSLOG_IDENTIFIER"));
 
                 nl = memchr(iov[i].iov_base, '\n', iov[i].iov_len);
                 if (nl) {
index f878dfc911a719a0501f961264a2e9b228f5d905..ec9afa187de97be3fd9245219843cba637527b24 100644 (file)
@@ -158,23 +158,23 @@ void server_process_native_message(
                                  * of this entry for the rate limiting
                                  * logic */
                                 if (l == 10 &&
-                                    memcmp(p, "PRIORITY=", 9) == 0 &&
+                                    hasprefix(p, "PRIORITY=") &&
                                     p[9] >= '0' && p[9] <= '9')
                                         priority = (priority & LOG_FACMASK) | (p[9] - '0');
 
                                 else if (l == 17 &&
-                                         memcmp(p, "SYSLOG_FACILITY=", 16) == 0 &&
+                                         hasprefix(p, "SYSLOG_FACILITY=") &&
                                          p[16] >= '0' && p[16] <= '9')
                                         priority = (priority & LOG_PRIMASK) | ((p[16] - '0') << 3);
 
                                 else if (l == 18 &&
-                                         memcmp(p, "SYSLOG_FACILITY=", 16) == 0 &&
+                                         hasprefix(p, "SYSLOG_FACILITY=") &&
                                          p[16] >= '0' && p[16] <= '9' &&
                                          p[17] >= '0' && p[17] <= '9')
                                         priority = (priority & LOG_PRIMASK) | (((p[16] - '0')*10 + (p[17] - '0')) << 3);
 
                                 else if (l >= 19 &&
-                                         memcmp(p, "SYSLOG_IDENTIFIER=", 18) == 0) {
+                                         hasprefix(p, "SYSLOG_IDENTIFIER=")) {
                                         char *t;
 
                                         t = strndup(p + 18, l - 18);
@@ -183,7 +183,7 @@ void server_process_native_message(
                                                 identifier = t;
                                         }
                                 } else if (l >= 8 &&
-                                           memcmp(p, "MESSAGE=", 8) == 0) {
+                                           hasprefix(p, "MESSAGE=")) {
                                         char *t;
 
                                         t = strndup(p + 8, l - 8);
index 95e625be096167ba987550fb230c15e0bec963ff..750acfe6d5386dcfad5ff31a6c9ce494baf5964d 100644 (file)
@@ -555,22 +555,22 @@ static int bus_match_find_leaf(
 enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n) {
         assert(k);
 
-        if (n == 4 && memcmp(k, "type", 4) == 0)
+        if (n == 4 && hasprefix(k, "type"))
                 return BUS_MATCH_MESSAGE_TYPE;
-        if (n == 6 && memcmp(k, "sender", 6) == 0)
+        if (n == 6 && hasprefix(k, "sender"))
                 return BUS_MATCH_SENDER;
-        if (n == 11 && memcmp(k, "destination", 11) == 0)
+        if (n == 11 && hasprefix(k, "destination"))
                 return BUS_MATCH_DESTINATION;
-        if (n == 9 && memcmp(k, "interface", 9) == 0)
+        if (n == 9 && hasprefix(k, "interface"))
                 return BUS_MATCH_INTERFACE;
-        if (n == 6 && memcmp(k, "member", 6) == 0)
+        if (n == 6 && hasprefix(k, "member"))
                 return BUS_MATCH_MEMBER;
-        if (n == 4 && memcmp(k, "path", 4) == 0)
+        if (n == 4 && hasprefix(k, "path"))
                 return BUS_MATCH_PATH;
-        if (n == 14 && memcmp(k, "path_namespace", 14) == 0)
+        if (n == 14 && hasprefix(k, "path_namespace"))
                 return BUS_MATCH_PATH_NAMESPACE;
 
-        if (n == 4 && memcmp(k, "arg", 3) == 0) {
+        if (n == 4 && hasprefix(k, "arg")) {
                 int j;
 
                 j = undecchar(k[3]);
@@ -580,7 +580,7 @@ enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n
                 return BUS_MATCH_ARG + j;
         }
 
-        if (n == 5 && memcmp(k, "arg", 3) == 0) {
+        if (n == 5 && hasprefix(k, "arg")) {
                 int a, b;
                 enum bus_match_node_type t;
 
@@ -596,7 +596,7 @@ enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n
                 return t;
         }
 
-        if (n == 8 && memcmp(k, "arg", 3) == 0 && memcmp(k + 4, "path", 4) == 0) {
+        if (n == 8 && hasprefix(k, "arg") && hasprefix(k + 4, "path")) {
                 int j;
 
                 j = undecchar(k[3]);
@@ -606,7 +606,7 @@ enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n
                 return BUS_MATCH_ARG_PATH + j;
         }
 
-        if (n == 9 && memcmp(k, "arg", 3) == 0 && memcmp(k + 5, "path", 4) == 0) {
+        if (n == 9 && hasprefix(k, "arg") && hasprefix(k + 5, "path")) {
                 enum bus_match_node_type t;
                 int a, b;
 
@@ -622,7 +622,7 @@ enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n
                 return t;
         }
 
-        if (n == 13 && memcmp(k, "arg", 3) == 0 && memcmp(k + 4, "namespace", 9) == 0) {
+        if (n == 13 && hasprefix(k, "arg") && hasprefix(k + 4, "namespace")) {
                 int j;
 
                 j = undecchar(k[3]);
@@ -632,7 +632,7 @@ enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n
                 return BUS_MATCH_ARG_NAMESPACE + j;
         }
 
-        if (n == 14 && memcmp(k, "arg", 3) == 0 && memcmp(k + 5, "namespace", 9) == 0) {
+        if (n == 14 && hasprefix(k, "arg") && hasprefix(k + 5, "namespace")) {
                 enum bus_match_node_type t;
                 int a, b;
 
index 40efad3273d3b94688abf2c98806265cd6c87c2a..89f67f52c044643e799c9d9ea7ca4b898c703b44 100644 (file)
@@ -438,7 +438,7 @@ static int output_export(
                 /* We already printed the boot id, from the data in
                  * the header, hence let's suppress it here */
                 if (length >= 9 &&
-                    memcmp(data, "_BOOT_ID=", 9) == 0)
+                    hasprefix(data, "_BOOT_ID="))
                         continue;
 
                 if (!utf8_is_printable(data, length)) {
index bfe03f2ae055ce713d07ef16dc53b3cf8a9229bd..969329d152368127cd38e133dc4db6b50ae4334d 100644 (file)
@@ -186,6 +186,8 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) {
 
 #define char_array_0(x) x[sizeof(x)-1] = 0;
 
+#define hasprefix(s, prefix) (memcmp(s, prefix, strlen(prefix)) == 0)
+
 #define IOVEC_SET_STRING(i, s)                  \
         do {                                    \
                 struct iovec *_i = &(i);        \