1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-27 01:55:22 +03:00

udev: replace ARRAY_SIZE() with ELEMENTSOF()

This commit is contained in:
Kay Sievers 2012-04-16 03:13:22 +02:00
parent b59e246565
commit 8fef0ff25c
10 changed files with 19 additions and 20 deletions

View File

@ -296,7 +296,7 @@ _public_ int udev_monitor_filter_update(struct udev_monitor *udev_monitor)
/* matched, pass packet */
bpf_stmt(ins, &i, BPF_RET|BPF_K, 0xffffffff);
if (i+1 >= ARRAY_SIZE(ins))
if (i+1 >= ELEMENTSOF(ins))
return -1;
}

View File

@ -19,7 +19,6 @@
#include "macro.h"
#include "libudev.h"
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define READ_END 0
#define WRITE_END 1

View File

@ -99,7 +99,7 @@ static int builtin_firmware(struct udev_device *dev, int argc, char *argv[], boo
/* lookup firmware file */
uname(&kernel);
for (i = 0; i < ARRAY_SIZE(searchpath); i++) {
for (i = 0; i < ELEMENTSOF(searchpath); i++) {
util_strscpyl(fwpath, sizeof(fwpath), searchpath[i], kernel.release, "/", firmware, NULL);
fwfile = fopen(fwpath, "re");
if (fwfile != NULL)

View File

@ -44,7 +44,7 @@ int udev_builtin_init(struct udev *udev)
unsigned int i;
int err;
for (i = 0; i < ARRAY_SIZE(builtins); i++) {
for (i = 0; i < ELEMENTSOF(builtins); i++) {
if (builtins[i]->init) {
err = builtins[i]->init(udev);
if (err < 0)
@ -58,7 +58,7 @@ void udev_builtin_exit(struct udev *udev)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(builtins); i++)
for (i = 0; i < ELEMENTSOF(builtins); i++)
if (builtins[i]->exit)
builtins[i]->exit(udev);
}
@ -68,7 +68,7 @@ bool udev_builtin_validate(struct udev *udev)
unsigned int i;
bool change = false;
for (i = 0; i < ARRAY_SIZE(builtins); i++)
for (i = 0; i < ELEMENTSOF(builtins); i++)
if (builtins[i]->validate)
if (builtins[i]->validate(udev))
change = true;
@ -79,7 +79,7 @@ void udev_builtin_list(struct udev *udev)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(builtins); i++)
for (i = 0; i < ELEMENTSOF(builtins); i++)
fprintf(stderr, " %-12s %s\n", builtins[i]->name, builtins[i]->help);
}
@ -103,7 +103,7 @@ enum udev_builtin_cmd udev_builtin_lookup(const char *command)
pos = strchr(name, ' ');
if (pos)
pos[0] = '\0';
for (i = 0; i < ARRAY_SIZE(builtins); i++)
for (i = 0; i < ELEMENTSOF(builtins); i++)
if (strcmp(builtins[i]->name, name) == 0)
return i;
return UDEV_BUILTIN_MAX;

View File

@ -132,7 +132,7 @@ size_t udev_event_apply_format(struct udev_event *event, const char *src, char *
goto copy;
}
for (i = 0; i < ARRAY_SIZE(map); i++) {
for (i = 0; i < ELEMENTSOF(map); i++) {
if (strncmp(&from[1], map[i].name, strlen(map[i].name)) == 0) {
type = map[i].type;
from += strlen(map[i].name)+1;
@ -148,7 +148,7 @@ size_t udev_event_apply_format(struct udev_event *event, const char *src, char *
goto copy;
}
for (i = 0; i < ARRAY_SIZE(map); i++) {
for (i = 0; i < ELEMENTSOF(map); i++) {
if (from[1] == map[i].fmt) {
type = map[i].type;
from += 2;
@ -486,7 +486,7 @@ static void spawn_read(struct udev_event *event,
timeout = -1;
}
fdcount = epoll_wait(fd_ep, ev, ARRAY_SIZE(ev), timeout);
fdcount = epoll_wait(fd_ep, ev, ELEMENTSOF(ev), timeout);
if (fdcount < 0) {
if (errno == EINTR)
continue;

View File

@ -1131,7 +1131,7 @@ static int rule_add_key(struct rule_tmp *rule_tmp, enum token_type type,
token->key.type = type;
token->key.op = op;
rule_tmp->token_cur++;
if (rule_tmp->token_cur >= ARRAY_SIZE(rule_tmp->token)) {
if (rule_tmp->token_cur >= ELEMENTSOF(rule_tmp->token)) {
log_error("temporary rule array too small\n");
return -1;
}
@ -1344,7 +1344,7 @@ static int add_rule(struct udev_rules *rules, char *line,
};
unsigned int i;
for (i = 0; i < ARRAY_SIZE(blacklist); i++)
for (i = 0; i < ELEMENTSOF(blacklist); i++)
if (strcmp(attr, blacklist[i]) == 0) {
log_error("invalid ENV attribute, '%s' can not be set %s:%u\n", attr, filename, lineno);
continue;

View File

@ -44,7 +44,7 @@ static bool skip_attribute(const char *name)
};
unsigned int i;
for (i = 0; i < ARRAY_SIZE(skip); i++)
for (i = 0; i < ELEMENTSOF(skip); i++)
if (strcmp(name, skip[i]) == 0)
return true;
return false;

View File

@ -253,7 +253,7 @@ static int adm_monitor(struct udev *udev, int argc, char *argv[])
struct epoll_event ev[4];
int i;
fdcount = epoll_wait(fd_ep, ev, ARRAY_SIZE(ev), -1);
fdcount = epoll_wait(fd_ep, ev, ELEMENTSOF(ev), -1);
if (fdcount < 0) {
if (errno != EINTR)
fprintf(stderr, "error receiving uevent message: %m\n");

View File

@ -67,7 +67,7 @@ static int adm_help(struct udev *udev, int argc, char *argv[])
unsigned int i;
fprintf(stderr, "Usage: udevadm [--help] [--version] [--debug] COMMAND [COMMAND OPTIONS]\n");
for (i = 0; i < ARRAY_SIZE(udevadm_cmds); i++)
for (i = 0; i < ELEMENTSOF(udevadm_cmds); i++)
if (udevadm_cmds[i]->help != NULL)
printf(" %-12s %s\n", udevadm_cmds[i]->name, udevadm_cmds[i]->help);
fprintf(stderr, "\n");
@ -131,7 +131,7 @@ int main(int argc, char *argv[])
log_debug("runtime dir '%s'\n", udev_get_run_path(udev));
if (command != NULL)
for (i = 0; i < ARRAY_SIZE(udevadm_cmds); i++) {
for (i = 0; i < ELEMENTSOF(udevadm_cmds); i++) {
if (strcmp(udevadm_cmds[i]->name, command) == 0) {
argc -= optind;
argv += optind;

View File

@ -327,7 +327,7 @@ static void worker_new(struct event *event)
int fdcount;
int i;
fdcount = epoll_wait(fd_ep, ev, ARRAY_SIZE(ev), -1);
fdcount = epoll_wait(fd_ep, ev, ELEMENTSOF(ev), -1);
if (fdcount < 0) {
if (errno == EINTR)
continue;
@ -889,7 +889,7 @@ static void static_dev_create_links(struct udev *udev)
if (dir == NULL)
return;
for (i = 0; i < ARRAY_SIZE(stdlinks); i++) {
for (i = 0; i < ELEMENTSOF(stdlinks); i++) {
struct stat sb;
if (stat(stdlinks[i].target, &sb) == 0) {
@ -1496,7 +1496,7 @@ int main(int argc, char *argv[])
/* kill idle or hanging workers */
timeout = 3 * 1000;
}
fdcount = epoll_wait(fd_ep, ev, ARRAY_SIZE(ev), timeout);
fdcount = epoll_wait(fd_ep, ev, ELEMENTSOF(ev), timeout);
if (fdcount < 0)
continue;