tree-wide: use IN_SET macro (#6977)

This commit is contained in:
Yu Watanabe
2017-10-04 16:01:32 +02:00
committed by Zbigniew Jędrzejewski-Szmek
parent 6d0aa4db7b
commit 4c70109600
92 changed files with 168 additions and 191 deletions
+6 -10
View File
@@ -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;
+5 -7
View File
@@ -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");
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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)) {
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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.
+2 -4
View File
@@ -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);
+2 -2
View File
@@ -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;
+1 -1
View File
@@ -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) {
+2 -2
View File
@@ -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;
+2 -2
View File
@@ -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 */
+1 -1
View File
@@ -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');
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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 == '/') {
+1 -1
View File
@@ -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;
+1 -2
View File
@@ -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;
}
+1 -1
View File
@@ -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);
}
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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);