-
Notifications
You must be signed in to change notification settings - Fork 307
/
14.9.c
53 lines (41 loc) · 1.1 KB
/
14.9.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <stropts.h>
#define FMNAMESZ 8
int main(int argc, char *argv[])
{
int fd, i, nmods;
struct str_list list;
if (2 != argc) {
printf("usage: %s <pathname>\n", argv[0]);
exit(-1);
}
if ((fd = open(argv[1], O_RDONLY)) < 0) {
printf("can't open %s\n", argv[1]);
exit(-1);
}
if (0 == isastream(fd)) {
printf("%s is not a stream\n", argv[1]);
exit(-1);
}
if ((nmods = ioctl(fd, I_LIST, (void *)0)) < 0) {
printf("I_LIST error for nmods\n");
exit(-1);
}
printf("#modules = %d\n", nmods);
list.sl_modlist = calloc(nmods, sizeof(struct str_mlist));
if (NULL == list.sl_modlist) {
printf("calloc error\n");
exit(-1);
}
list.sl_nmods = nmods;
if (ioctl(fd, I_LIST, &list) < 0) {
printf("I_LIST error for list\n");
exit(-1);
}
for (i = 1; i < nmods; i++) {
printf(" %s: %s\n", (i == nmods) ? "deriver" : "module", list.sl_modlist++->l_name);
}
exit(0);
}