int err;
size_t len = 0;
- static const char *const names[] = { "pcspkr", "pcspkr2", "floppy", "ext4", NULL};
- const char **name;
+ static const char *const names[] = { "pcspkr", "pcspkr2", "floppy", "ext4" };
ctx = kmod_new(NULL, NULL);
if (ctx == NULL)
exit(EXIT_FAILURE);
- for (name = names; *name; name++) {
- err = kmod_module_new_from_name(ctx, *name, &mod);
+ for (size_t i = 0; i < ARRAY_SIZE(names); i++) {
+ err = kmod_module_new_from_name(ctx, names[i], &mod);
if (err < 0)
goto fail_lookup;
list = kmod_list_append(list, mod);
"snd-hda-intel",
"snd-timer",
"iTCO_wdt",
- NULL,
// clang-format on
};
- const char *const *p;
struct kmod_ctx *ctx;
struct kmod_module *mod;
const char *null_config = NULL;
if (ctx == NULL)
exit(EXIT_FAILURE);
- for (p = modnames; p != NULL; p++) {
- err = kmod_module_new_from_name(ctx, *p, &mod);
+ for (size_t i = 0; i < ARRAY_SIZE(modnames); i++) {
+ err = kmod_module_new_from_name(ctx, modnames[i], &mod);
if (err < 0)
- exit(EXIT_SUCCESS);
+ exit(EXIT_FAILURE);
printf("modname: %s\n", kmod_module_get_name(mod));
kmod_module_unref(mod);
{
static const char *const modnames[] = {
"ext4.*",
- NULL,
};
- const char *const *p;
struct kmod_ctx *ctx;
int err;
if (ctx == NULL)
exit(EXIT_FAILURE);
- for (p = modnames; p != NULL; p++) {
+ for (size_t i = 0; i < ARRAY_SIZE(modnames); i++) {
struct kmod_list *l, *list = NULL;
- err = kmod_module_new_from_lookup(ctx, *p, &list);
+ err = kmod_module_new_from_lookup(ctx, modnames[i], &list);
if (err < 0)
- exit(EXIT_SUCCESS);
+ exit(EXIT_FAILURE);
kmod_list_foreach(l, list) {
struct kmod_module *m;
static int alias_1(void)
{
- static const char *const input[] = {
+ static const char *const aliases[] = {
// clang-format off
"test1234",
"test[abcfoobar]2211",
"bar[aaa][bbbb]sss",
"kmod[p.b]lib",
"[az]1234[AZ]",
- NULL,
// clang-format on
};
char buf[PATH_MAX];
size_t len;
- const char *const *alias;
- for (alias = input; *alias != NULL; alias++) {
+ for (size_t i = 0; i < ARRAY_SIZE(aliases); i++) {
int ret;
- ret = alias_normalize(*alias, buf, &len);
- printf("input %s\n", *alias);
+ ret = alias_normalize(aliases[i], buf, &len);
+ printf("input %s\n", aliases[i]);
printf("return %d\n", ret);
if (ret == 0) {
const char *val;
bool res;
} teststr[] = {
+ // clang-format off
{ "/bla.ko", true },
#if ENABLE_ZLIB
{ "/bla.ko.gz", true },
{ "/bla.ko.", false },
{ "/bla.koz", false },
{ "/b", false },
- { },
- }, *iter;
+ // clang-format on
+ };
- for (iter = &teststr[0]; iter->val != NULL; iter++) {
- assert_return(path_ends_with_kmod_ext(iter->val, strlen(iter->val)) ==
- iter->res,
+ for (size_t i = 0; i < ARRAY_SIZE(teststr); i++) {
+ assert_return(path_ends_with_kmod_ext(teststr[i].val,
+ strlen(teststr[i].val)) ==
+ teststr[i].res,
EXIT_FAILURE);
}
test_spawn_prog(TOOLS_DIR "/modprobe", \
(const char *[]){ TOOLS_DIR "/modprobe", ##__VA_ARGS__, NULL })
-static const char *const mod_name[] = {
- "mod-loop-b",
- "mod-weakdep",
- NULL,
-};
-
static int test_weakdep(void)
{
+ static const char *const mod_name[] = {
+ "mod-loop-b",
+ "mod-weakdep",
+ };
struct kmod_ctx *ctx;
- int mod_name_index = 0;
int err;
ctx = kmod_new(NULL, NULL);
if (ctx == NULL)
exit(EXIT_FAILURE);
- while (mod_name[mod_name_index]) {
+ for (size_t i = 0; i < ARRAY_SIZE(mod_name); i++) {
struct kmod_list *list = NULL;
struct kmod_module *mod = NULL;
struct kmod_list *mod_list = NULL;
struct kmod_list *itr = NULL;
- printf("%s:", mod_name[mod_name_index]);
- err = kmod_module_new_from_lookup(ctx, mod_name[mod_name_index], &list);
+ printf("%s:", mod_name[i]);
+ err = kmod_module_new_from_lookup(ctx, mod_name[i], &list);
if (list == NULL || err < 0) {
fprintf(stderr, "module %s not found in directory %s\n",
- mod_name[mod_name_index],
- ctx ? kmod_get_dirname(ctx) : "(missing)");
+ mod_name[i], ctx ? kmod_get_dirname(ctx) : "(missing)");
exit(EXIT_FAILURE);
}
err = kmod_module_get_weakdeps(mod, &mod_list);
if (err) {
fprintf(stderr, "weak dependencies can not be read for %s (%d)\n",
- mod_name[mod_name_index], err);
+ mod_name[i], err);
exit(EXIT_FAILURE);
}
kmod_module_unref_list(mod_list);
kmod_module_unref(mod);
kmod_module_unref_list(list);
-
- mod_name_index++;
}
kmod_unref(ctx);