summaryrefslogtreecommitdiff
path: root/src/basic
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2017-10-04 23:01:32 +0900
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-10-04 16:01:32 +0200
commit4c701096002fff540d9ddb3b21398c551ac3af78 (patch)
tree537e654dc92baa5eed5b6ff69867114384ecfa47 /src/basic
parent6d0aa4db7b33c9ce71b820c76428a1cfd24fb56f (diff)
downloadsystemd-4c701096002fff540d9ddb3b21398c551ac3af78.tar.gz
tree-wide: use IN_SET macro (#6977)
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/calendarspec.c16
-rw-r--r--src/basic/cgroup-util.c12
-rw-r--r--src/basic/env-util.c2
-rw-r--r--src/basic/escape.c2
-rw-r--r--src/basic/extract-word.c2
-rw-r--r--src/basic/fs-util.c2
-rw-r--r--src/basic/hashmap.c2
-rw-r--r--src/basic/hostname-util.c6
-rw-r--r--src/basic/mount-util.c4
-rw-r--r--src/basic/parse-util.c2
-rw-r--r--src/basic/process-util.c4
-rw-r--r--src/basic/rm-rf.c4
-rw-r--r--src/basic/socket-util.c2
-rw-r--r--src/basic/string-util.c2
-rw-r--r--src/basic/time-util.c2
-rw-r--r--src/basic/unit-name.c2
-rw-r--r--src/basic/user-util.c3
-rw-r--r--src/basic/utf8.c2
-rw-r--r--src/basic/xattr-util.c2
-rw-r--r--src/basic/xml.c2
20 files changed, 33 insertions, 42 deletions
diff --git a/src/basic/calendarspec.c b/src/basic/calendarspec.c
index be7328af40..1fc9e9b154 100644
--- a/src/basic/calendarspec.c
+++ b/src/basic/calendarspec.c
@@ -421,11 +421,7 @@ static int parse_weekdays(const char **p, CalendarSpec *c) {
skip = strlen(day_nr[i].name);
- if ((*p)[skip] != '-' &&
- (*p)[skip] != '.' &&
- (*p)[skip] != ',' &&
- (*p)[skip] != ' ' &&
- (*p)[skip] != 0)
+ if (!IN_SET((*p)[skip], 0, '-', '.', ',', ' '))
return -EINVAL;
c->weekdays_bits |= 1 << day_nr[i].nr;
@@ -484,7 +480,7 @@ static int parse_weekdays(const char **p, CalendarSpec *c) {
}
/* Allow a trailing comma but not an open range */
- if (**p == 0 || **p == ' ') {
+ if (IN_SET(**p, 0, ' ')) {
*p += strspn(*p, " ");
return l < 0 ? 0 : -EINVAL;
}
@@ -644,7 +640,7 @@ static int prepend_component(const char **p, bool usec, CalendarComponent **c) {
return -ERANGE;
}
- if (*e != 0 && *e != ' ' && *e != ',' && *e != '-' && *e != '~' && *e != ':')
+ if (!IN_SET(*e, 0, ' ', ',', '-', '~', ':'))
return -EINVAL;
cc = new0(CalendarComponent, 1);
@@ -741,7 +737,7 @@ static int parse_date(const char **p, CalendarSpec *c) {
return r;
/* Already the end? A ':' as separator? In that case this was a time, not a date */
- if (*t == 0 || *t == ':') {
+ if (IN_SET(*t, 0, ':')) {
free_chain(first);
return 0;
}
@@ -761,7 +757,7 @@ static int parse_date(const char **p, CalendarSpec *c) {
}
/* Got two parts, hence it's month and day */
- if (*t == ' ' || *t == 0) {
+ if (IN_SET(*t, 0, ' ')) {
*p = t + strspn(t, " ");
c->month = first;
c->day = second;
@@ -789,7 +785,7 @@ static int parse_date(const char **p, CalendarSpec *c) {
}
/* Got three parts, hence it is year, month and day */
- if (*t == ' ' || *t == 0) {
+ if (IN_SET(*t, 0, ' ')) {
*p = t + strspn(t, " ");
c->year = first;
c->month = second;
diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c
index f3f6a21576..d51c3efd22 100644
--- a/src/basic/cgroup-util.c
+++ b/src/basic/cgroup-util.c
@@ -374,7 +374,7 @@ int cg_kill_recursive(
if (flags & CGROUP_REMOVE) {
r = cg_rmdir(controller, path);
- if (r < 0 && ret >= 0 && r != -ENOENT && r != -EBUSY)
+ if (r < 0 && ret >= 0 && !IN_SET(r, -ENOENT, -EBUSY))
return r;
}
@@ -509,7 +509,7 @@ int cg_migrate_recursive(
if (flags & CGROUP_REMOVE) {
r = cg_rmdir(cfrom, pfrom);
- if (r < 0 && ret >= 0 && r != -ENOENT && r != -EBUSY)
+ if (r < 0 && ret >= 0 && !IN_SET(r, -ENOENT, -EBUSY))
return r;
}
@@ -1883,9 +1883,7 @@ char *cg_escape(const char *p) {
/* The return value of this function (unlike cg_unescape())
* needs free()! */
- if (p[0] == 0 ||
- p[0] == '_' ||
- p[0] == '.' ||
+ if (IN_SET(p[0], 0, '_', '.') ||
streq(p, "notify_on_release") ||
streq(p, "release_agent") ||
streq(p, "tasks") ||
@@ -1951,7 +1949,7 @@ bool cg_controller_is_valid(const char *p) {
if (s)
p = s;
- if (*p == 0 || *p == '_')
+ if (IN_SET(*p, 0, '_'))
return false;
for (t = p; *t; t++)
@@ -2003,7 +2001,7 @@ int cg_slice_to_path(const char *unit, char **ret) {
char n[dash - p + sizeof(".slice")];
/* Don't allow trailing or double dashes */
- if (dash[1] == 0 || dash[1] == '-')
+ if (IN_SET(dash[1], 0, '-'))
return -EINVAL;
strcpy(stpncpy(n, p, dash - p), ".slice");
diff --git a/src/basic/env-util.c b/src/basic/env-util.c
index d72940acb3..fa42edfa96 100644
--- a/src/basic/env-util.c
+++ b/src/basic/env-util.c
@@ -707,7 +707,7 @@ char **replace_env_argv(char **argv, char **env) {
STRV_FOREACH(i, argv) {
/* If $FOO appears as single word, replace it by the split up variable */
- if ((*i)[0] == '$' && (*i)[1] != '{' && (*i)[1] != '$') {
+ if ((*i)[0] == '$' && !IN_SET((*i)[1], '{', '$')) {
char *e;
char **w, **m = NULL;
unsigned q;
diff --git a/src/basic/escape.c b/src/basic/escape.c
index 22b8b04156..0a6122c64a 100644
--- a/src/basic/escape.c
+++ b/src/basic/escape.c
@@ -426,7 +426,7 @@ char *octescape(const char *s, size_t len) {
for (f = s, t = r; f < s + len; f++) {
- if (*f < ' ' || *f >= 127 || *f == '\\' || *f == '"') {
+ if (*f < ' ' || *f >= 127 || IN_SET(*f, '\\', '"')) {
*(t++) = '\\';
*(t++) = '0' + (*f >> 6);
*(t++) = '0' + ((*f >> 3) & 8);
diff --git a/src/basic/extract-word.c b/src/basic/extract-word.c
index 804f14c44c..f4ac526eb1 100644
--- a/src/basic/extract-word.c
+++ b/src/basic/extract-word.c
@@ -152,7 +152,7 @@ int extract_first_word(const char **p, char **ret, const char *separators, Extra
for (;; (*p)++, c = **p) {
if (c == 0)
goto finish_force_terminate;
- else if ((c == '\'' || c == '"') && (flags & EXTRACT_QUOTES)) {
+ else if (IN_SET(c, '\'', '"') && (flags & EXTRACT_QUOTES)) {
quote = c;
break;
} else if (c == '\\' && !(flags & EXTRACT_RETAIN_ESCAPE)) {
diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c
index af63171041..b90f343ed3 100644
--- a/src/basic/fs-util.c
+++ b/src/basic/fs-util.c
@@ -324,7 +324,7 @@ int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gi
mkdir_parents(path, 0755);
fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY,
- (mode == 0 || mode == MODE_INVALID) ? 0644 : mode);
+ IN_SET(mode, 0, MODE_INVALID) ? 0644 : mode);
if (fd < 0)
return -errno;
diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c
index 6ef1b0ba35..a5ab4570fa 100644
--- a/src/basic/hashmap.c
+++ b/src/basic/hashmap.c
@@ -508,7 +508,7 @@ static void base_remove_entry(HashmapBase *h, unsigned idx) {
/* Find the stop bucket ("right"). It is either free or has DIB == 0. */
for (right = next_idx(h, left); ; right = next_idx(h, right)) {
raw_dib = dibs[right];
- if (raw_dib == 0 || raw_dib == DIB_RAW_FREE)
+ if (IN_SET(raw_dib, 0, DIB_RAW_FREE))
break;
/* The buckets are not supposed to be all occupied and with DIB > 0.
diff --git a/src/basic/hostname-util.c b/src/basic/hostname-util.c
index b511a36301..ea9e77087f 100644
--- a/src/basic/hostname-util.c
+++ b/src/basic/hostname-util.c
@@ -90,9 +90,7 @@ static bool hostname_valid_char(char c) {
(c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') ||
- c == '-' ||
- c == '_' ||
- c == '.';
+ IN_SET(c, '-', '_', '.');
}
/**
@@ -235,7 +233,7 @@ int read_hostname_config(const char *path, char **hostname) {
/* may have comments, ignore them */
FOREACH_LINE(l, f, return -errno) {
truncate_nl(l);
- if (l[0] != '\0' && l[0] != '#') {
+ if (!IN_SET(l[0], '\0', '#')) {
/* found line with value */
name = hostname_cleanup(l);
name = strdup(name);
diff --git a/src/basic/mount-util.c b/src/basic/mount-util.c
index 8c1d2bc9c9..65b488351e 100644
--- a/src/basic/mount-util.c
+++ b/src/basic/mount-util.c
@@ -472,14 +472,14 @@ int bind_remount_recursive_with_mountinfo(const char *prefix, bool ro, char **bl
while ((x = set_steal_first(todo))) {
r = set_consume(done, x);
- if (r == -EEXIST || r == 0)
+ if (IN_SET(r, 0, -EEXIST))
continue;
if (r < 0)
return r;
/* Deal with mount points that are obstructed by a later mount */
r = path_is_mount_point(x, NULL, 0);
- if (r == -ENOENT || r == 0)
+ if (IN_SET(r, 0, -ENOENT))
continue;
if (r < 0)
return r;
diff --git a/src/basic/parse-util.c b/src/basic/parse-util.c
index 89bb667c5f..4ae07b0a8e 100644
--- a/src/basic/parse-util.c
+++ b/src/basic/parse-util.c
@@ -152,7 +152,7 @@ int parse_size(const char *t, uint64_t base, uint64_t *size) {
unsigned n_entries, start_pos = 0;
assert(t);
- assert(base == 1000 || base == 1024);
+ assert(IN_SET(base, 1000, 1024));
assert(size);
if (base == 1000) {
diff --git a/src/basic/process-util.c b/src/basic/process-util.c
index ab661a8f16..a1b50b6c79 100644
--- a/src/basic/process-util.c
+++ b/src/basic/process-util.c
@@ -392,7 +392,7 @@ int is_kernel_thread(pid_t pid) {
bool eof;
FILE *f;
- if (pid == 0 || pid == 1 || pid == getpid_cached()) /* pid 1, and we ourselves certainly aren't a kernel thread */
+ if (IN_SET(pid, 0, 1) || pid == getpid_cached()) /* pid 1, and we ourselves certainly aren't a kernel thread */
return 0;
assert(pid > 1);
@@ -817,7 +817,7 @@ bool pid_is_alive(pid_t pid) {
return true;
r = get_process_state(pid);
- if (r == -ESRCH || r == 'Z')
+ if (IN_SET(r, -ESRCH, 'Z'))
return false;
return true;
diff --git a/src/basic/rm-rf.c b/src/basic/rm-rf.c
index 77fe88e42c..0bbafb4cd7 100644
--- a/src/basic/rm-rf.c
+++ b/src/basic/rm-rf.c
@@ -132,7 +132,7 @@ int rm_rf_children(int fd, RemoveFlags flags, struct stat *root_dev) {
r = btrfs_subvol_remove_fd(fd, de->d_name, BTRFS_REMOVE_RECURSIVE|BTRFS_REMOVE_QUOTA);
if (r < 0) {
- if (r != -ENOTTY && r != -EINVAL) {
+ if (!IN_SET(r, -ENOTTY, -EINVAL)) {
if (ret == 0)
ret = r;
@@ -193,7 +193,7 @@ int rm_rf(const char *path, RemoveFlags flags) {
if (r >= 0)
return r;
- if (r != -ENOTTY && r != -EINVAL && r != -ENOTDIR)
+ if (!IN_SET(r, -ENOTTY, -EINVAL, -ENOTDIR))
return r;
/* Not btrfs or not a subvolume */
diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c
index e8d39674cc..5942b2df9b 100644
--- a/src/basic/socket-util.c
+++ b/src/basic/socket-util.c
@@ -892,7 +892,7 @@ bool ifname_valid(const char *p) {
if ((unsigned char) *p <= 32U)
return false;
- if (*p == ':' || *p == '/')
+ if (IN_SET(*p, ':', '/'))
return false;
numeric = numeric && (*p >= '0' && *p <= '9');
diff --git a/src/basic/string-util.c b/src/basic/string-util.c
index 5808b1280e..2eed99d9c0 100644
--- a/src/basic/string-util.c
+++ b/src/basic/string-util.c
@@ -673,7 +673,7 @@ char *strip_tab_ansi(char **ibuf, size_t *_isz) {
case STATE_BRACKET:
if (i >= *ibuf + isz || /* EOT */
- (!(*i >= '0' && *i <= '9') && *i != ';' && *i != 'm')) {
+ (!(*i >= '0' && *i <= '9') && !IN_SET(*i, ';', 'm'))) {
fputc_unlocked('\x1B', f);
fputc_unlocked('[', f);
state = STATE_OTHER;
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
index f67467c5bd..46ec722989 100644
--- a/src/basic/time-util.c
+++ b/src/basic/time-util.c
@@ -1308,7 +1308,7 @@ bool timezone_is_valid(const char *name) {
if (!(*p >= '0' && *p <= '9') &&
!(*p >= 'a' && *p <= 'z') &&
!(*p >= 'A' && *p <= 'Z') &&
- !(*p == '-' || *p == '_' || *p == '+' || *p == '/'))
+ !IN_SET(*p, '-', '_', '+', '/'))
return false;
if (*p == '/') {
diff --git a/src/basic/unit-name.c b/src/basic/unit-name.c
index 5e3f307dcd..f9c034c94b 100644
--- a/src/basic/unit-name.c
+++ b/src/basic/unit-name.c
@@ -305,7 +305,7 @@ static char *do_escape(const char *f, char *t) {
for (; *f; f++) {
if (*f == '/')
*(t++) = '-';
- else if (*f == '-' || *f == '\\' || !strchr(VALID_CHARS, *f))
+ else if (IN_SET(*f, '-', '\\') || !strchr(VALID_CHARS, *f))
t = do_escape_char(*f, t);
else
*(t++) = *f;
diff --git a/src/basic/user-util.c b/src/basic/user-util.c
index c619dad527..a691a0d3fc 100644
--- a/src/basic/user-util.c
+++ b/src/basic/user-util.c
@@ -543,8 +543,7 @@ bool valid_user_group_name(const char *u) {
if (!(*i >= 'a' && *i <= 'z') &&
!(*i >= 'A' && *i <= 'Z') &&
!(*i >= '0' && *i <= '9') &&
- *i != '_' &&
- *i != '-')
+ !IN_SET(*i, '_', '-'))
return false;
}
diff --git a/src/basic/utf8.c b/src/basic/utf8.c
index 6eae2b983d..7a52fac621 100644
--- a/src/basic/utf8.c
+++ b/src/basic/utf8.c
@@ -73,7 +73,7 @@ static bool unichar_is_control(char32_t ch) {
'\t' is in C0 range, but more or less harmless and commonly used.
*/
- return (ch < ' ' && ch != '\t' && ch != '\n') ||
+ return (ch < ' ' && !IN_SET(ch, '\t', '\n')) ||
(0x7F <= ch && ch <= 0x9F);
}
diff --git a/src/basic/xattr-util.c b/src/basic/xattr-util.c
index 8256899eda..e086376d7c 100644
--- a/src/basic/xattr-util.c
+++ b/src/basic/xattr-util.c
@@ -129,7 +129,7 @@ static int parse_crtime(le64_t le, usec_t *usec) {
assert(usec);
u = le64toh(le);
- if (u == 0 || u == (uint64_t) -1)
+ if (IN_SET(u, 0, (uint64_t) -1))
return -EIO;
*usec = (usec_t) u;
diff --git a/src/basic/xml.c b/src/basic/xml.c
index 1dbeac7324..a4337f4865 100644
--- a/src/basic/xml.c
+++ b/src/basic/xml.c
@@ -208,7 +208,7 @@ int xml_tokenize(const char **p, char **name, void **state, unsigned *line) {
if (*c == '=') {
c++;
- if (*c == '\'' || *c == '\"') {
+ if (IN_SET(*c, '\'', '\"')) {
/* Tag with a quoted value */
e = strchr(c+1, *c);