]> git.ipfire.org Git - thirdparty/kmod.git/blame - test/test-get-dependencies.c
API-BREAK: kmod_new() takes a second parameter for configuration directory.
[thirdparty/kmod.git] / test / test-get-dependencies.c
CommitLineData
1843b153
LDM
1#include <stdio.h>
2#include <stdlib.h>
3#include <stddef.h>
4#include <errno.h>
5#include <unistd.h>
6#include <inttypes.h>
7#include <string.h>
8#include <libkmod.h>
9
10
11int main(int argc, char *argv[])
12{
13 const char *name;
14 struct kmod_ctx *ctx;
15 struct kmod_module *mod;
16 struct kmod_list *list, *l;
17 int err;
18
19 printf("libkmod version %s\n", VERSION);
20
21 if (argc < 2) {
22 fprintf(stderr, "ERR: Provide a module name\n");
23 return EXIT_FAILURE;
24 }
25
26 name = argv[1];
27
cb8d4d3e 28 ctx = kmod_new(NULL, NULL);
1843b153
LDM
29 if (ctx == NULL)
30 exit(EXIT_FAILURE);
31
32 err = kmod_module_new_from_name(ctx, name, &mod);
33 if (err < 0) {
34 kmod_unref(ctx);
35 exit(EXIT_FAILURE);
36 }
37
38 list = kmod_module_get_dependencies(mod);
39 printf("Module: %s\nDependency list:\n", name);
40
41 kmod_list_foreach(l, list) {
42 struct kmod_module *m = kmod_module_get_module(l);
43 printf("\t%s\n", kmod_module_get_name(m));
44 kmod_module_unref(m);
45 }
46
47 kmod_module_unref_list(list);
48 kmod_module_unref(mod);
49 kmod_unref(ctx);
50
51 return EXIT_SUCCESS;
52}