NetBSD Wiki/examples/
drvctlio
#include <sys/ioctl.h>
#include <sys/drvctlio.h>
#include <err.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
int
main(int argc, char *argv[])
{
struct devlistargs l;
unsigned int i, children;
int drvfd;
if (argc != 2)
err(1, "args");
if ((drvfd = open(DRVCTLDEV, O_RDONLY, 0)) < 0)
err(1, "can't open " DRVCTLDEV);
strlcpy(l.l_devname, argv[1], sizeof(l.l_devname));
l.l_childname = NULL;
l.l_children = 0;
if (ioctl(drvfd, DRVLISTDEV, &l) == -1)
err(1, "DRVLISTDEV");
children = l.l_children;
l.l_childname = malloc(sizeof(l.l_childname[0]) * children);
if (ioctl(drvfd, DRVLISTDEV, &l) == -1)
err(1, "DRVLISTDEV");
if (l.l_children != children)
err(1, "number of children changed between ioctls");
if (l.l_childname == NULL) {
puts("No children.");
return 0;
}
for (i = 0; i < l.l_children; i++) {
puts(l.l_childname[i]);
}
close(drvfd);
return 0;
}
Add a comment