tree-wide: port various places over to STARTSWITH_SET()
authorLennart Poettering <lennart@poettering.net>
Fri, 23 Nov 2018 15:30:23 +0000 (16:30 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 26 Nov 2018 13:08:46 +0000 (14:08 +0100)
src/backlight/backlight.c
src/basic/path-util.c
src/core/load-fragment.c
src/cryptsetup/cryptsetup-generator.c
src/journal-remote/journal-remote-main.c
src/journal-remote/journal-upload.c
src/login/logind-core.c
src/run/run.c
src/shared/acl-util.c
src/shared/web-util.c
src/udev/udevd.c

index a866c68..780ad56 100644 (file)
@@ -44,9 +44,7 @@ static int find_pci_or_platform_parent(sd_device *device, sd_device **ret) {
                 c += strspn(c, DIGITS);
                 if (*c == '-') {
                         /* A connector DRM device, let's ignore all but LVDS and eDP! */
-
-                        if (!startswith(c, "-LVDS-") &&
-                            !startswith(c, "-Embedded DisplayPort-"))
+                        if (!STARTSWITH_SET(c, "-LVDS-", "-Embedded DisplayPort-"))
                                 return -EOPNOTSUPP;
                 }
 
index 2deb176..eb64c88 100644 (file)
@@ -919,8 +919,7 @@ bool valid_device_allow_pattern(const char *path) {
         /* Like valid_device_node_path(), but also allows full-subsystem expressions, like DeviceAllow= and DeviceDeny=
          * accept it */
 
-        if (startswith(path, "block-") ||
-            startswith(path, "char-"))
+        if (STARTSWITH_SET(path, "block-", "char-"))
                 return true;
 
         return valid_device_node_path(path);
index efefdae..ce222e4 100644 (file)
@@ -3242,7 +3242,7 @@ int config_parse_device_allow(
                 return 0;
         }
 
-        if (!startswith(resolved, "block-") && !startswith(resolved, "char-")) {
+        if (!STARTSWITH_SET(resolved, "block-", "char-")) {
 
                 r = path_simplify_and_warn(resolved, 0, unit, filename, line, lvalue);
                 if (r < 0)
index 7da13dc..b0b1065 100644 (file)
@@ -510,11 +510,9 @@ static int add_crypttab_devices(void) {
                         continue;
                 }
 
-                uuid = startswith(device, "UUID=");
+                uuid = STARTSWITH_SET(device, "UUID=", "luks-");
                 if (!uuid)
                         uuid = path_startswith(device, "/dev/disk/by-uuid/");
-                if (!uuid)
-                        uuid = startswith(name, "luks-");
                 if (uuid)
                         d = hashmap_get(arg_disks, uuid);
 
index 44f3450..02078dc 100644 (file)
@@ -630,10 +630,9 @@ static int create_remoteserver(
                 if (fd < 0)
                         return fd;
 
-                hostname =
-                        startswith(arg_url, "https://") ?:
-                        startswith(arg_url, "http://") ?:
-                        arg_url;
+                hostname = STARTSWITH_SET(arg_url, "https://", "http://");
+                if (!hostname)
+                        hostname = arg_url;
 
                 hostname = strdupa(hostname);
                 if ((p = strchr(hostname, '/')))
index f7b91fd..70d0fca 100644 (file)
@@ -25,6 +25,7 @@
 #include "sigbus.h"
 #include "signal-util.h"
 #include "string-util.h"
+#include "strv.h"
 #include "util.h"
 
 #define PRIV_KEY_FILE CERTIFICATE_ROOT "/private/journal-upload.pem"
@@ -408,7 +409,8 @@ static int setup_uploader(Uploader *u, const char *url, const char *state_file)
         memzero(u, sizeof(Uploader));
         u->input = -1;
 
-        if (!(host = startswith(url, "http://")) && !(host = startswith(url, "https://"))) {
+        host = STARTSWITH_SET(url, "http://", "https://");
+        if (!host) {
                 host = url;
                 proto = "https://";
         }
index 2bab2fd..60831bb 100644 (file)
@@ -606,9 +606,8 @@ static int manager_count_external_displays(Manager *m) {
                 return r;
 
         FOREACH_DEVICE(e, d) {
+                const char *status, *enabled, *dash, *nn, *subsys;
                 sd_device *p;
-                const char *status, *enabled, *dash, *nn, *i, *subsys;
-                bool external = false;
 
                 if (sd_device_get_parent(d, &p) < 0)
                         continue;
@@ -631,16 +630,10 @@ static int manager_count_external_displays(Manager *m) {
                         continue;
 
                 dash++;
-                FOREACH_STRING(i, "VGA-", "DVI-I-", "DVI-D-", "DVI-A-"
-                               "Composite-", "SVIDEO-", "Component-",
-                               "DIN-", "DP-", "HDMI-A-", "HDMI-B-", "TV-") {
-
-                        if (startswith(dash, i)) {
-                                external = true;
-                                break;
-                        }
-                }
-                if (!external)
+                if (!STARTSWITH_SET(dash,
+                                    "VGA-", "DVI-I-", "DVI-D-", "DVI-A-"
+                                    "Composite-", "SVIDEO-", "Component-",
+                                    "DIN-", "DP-", "HDMI-A-", "HDMI-B-", "TV-"))
                         continue;
 
                 /* Ignore ports that are not enabled */
index 0475156..e9e3128 100644 (file)
@@ -384,12 +384,13 @@ static int parse_argv(int argc, char *argv[]) {
                                 return log_oom();
 
                         with_timer = with_timer ||
-                                !!startswith(optarg, "OnActiveSec=") ||
-                                !!startswith(optarg, "OnBootSec=") ||
-                                !!startswith(optarg, "OnStartupSec=") ||
-                                !!startswith(optarg, "OnUnitActiveSec=") ||
-                                !!startswith(optarg, "OnUnitInactiveSec=") ||
-                                !!startswith(optarg, "OnCalendar=");
+                                STARTSWITH_SET(optarg,
+                                               "OnActiveSec=",
+                                               "OnBootSec=",
+                                               "OnStartupSec=",
+                                               "OnUnitActiveSec=",
+                                               "OnUnitInactiveSec=",
+                                               "OnCalendar=");
                         break;
 
                 case ARG_PATH_PROPERTY:
index 1eaf653..6f06571 100644 (file)
@@ -219,14 +219,11 @@ int parse_acl(const char *text, acl_t *acl_access, acl_t *acl_default, bool want
         STRV_FOREACH(entry, split) {
                 char *p;
 
-                p = startswith(*entry, "default:");
+                p = STARTSWITH_SET(*entry, "default:", "d:");
                 if (!p)
-                        p = startswith(*entry, "d:");
+                        p = *entry;
 
-                if (p)
-                        r = strv_push(&d, p);
-                else
-                        r = strv_push(&a, *entry);
+                r = strv_push(&d, p);
                 if (r < 0)
                         return r;
         }
index 82221af..edf650d 100644 (file)
@@ -3,6 +3,7 @@
 #include <stdbool.h>
 
 #include "string-util.h"
+#include "strv.h"
 #include "utf8.h"
 #include "web-util.h"
 
@@ -13,7 +14,7 @@ bool http_etag_is_valid(const char *etag) {
         if (!endswith(etag, "\""))
                 return false;
 
-        if (!startswith(etag, "\"") && !startswith(etag, "W/\""))
+        if (!STARTSWITH_SET(etag, "\"", "W/\""))
                 return false;
 
         return true;
@@ -25,9 +26,7 @@ bool http_url_is_valid(const char *url) {
         if (isempty(url))
                 return false;
 
-        p = startswith(url, "http://");
-        if (!p)
-                p = startswith(url, "https://");
+        p = STARTSWITH_SET(url, "http://", "https://");
         if (!p)
                 return false;
 
@@ -46,12 +45,7 @@ bool documentation_url_is_valid(const char *url) {
         if (http_url_is_valid(url))
                 return true;
 
-        p = startswith(url, "file:/");
-        if (!p)
-                p = startswith(url, "info:");
-        if (!p)
-                p = startswith(url, "man:");
-
+        p = STARTSWITH_SET(url, "file:/", "info:", "man:");
         if (isempty(p))
                 return false;
 
index 6eacfe8..9c8e7f9 100644 (file)
@@ -57,6 +57,7 @@
 #include "signal-util.h"
 #include "socket-util.h"
 #include "string-util.h"
+#include "strv.h"
 #include "strxcpyx.h"
 #include "syslog-util.h"
 #include "udev-builtin.h"
@@ -361,9 +362,7 @@ static int worker_lock_block_device(sd_device *dev, int *ret_fd) {
         if (r < 0)
                 return log_device_debug_errno(dev, r, "Failed to get sysname: %m");
 
-        if (startswith(val, "dm-") ||
-            startswith(val, "md") ||
-            startswith(val, "drbd"))
+        if (STARTSWITH_SET(val, "dm-", "md", "drbd"))
                 return 0;
 
         r = sd_device_get_devtype(dev, &val);