Ticket #7135: udev.c

File udev.c, 1.1 KB (added by Bill Meek <llibkeem@…>, 14 years ago)

Standalone udev library test.

Line 
1#include <stdio.h>
2
3/*
4 * sudo apt-get install libudev-dev
5 * cc -ludev -o udev udev.c
6 */
7
8/* Next line required at least in mythubuntu 9.04 */
9#define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE
10#include <libudev.h>
11
12main()
13{
14    udevTest("/sys/block/sda");
15    udevTest("/sys/block/sdb");
16    udevTest("/sys/block/sdc");
17    udevTest("/sys/block/sr0");
18    udevTest("/sys/block/sdfoo");
19    return(0);
20}
21
22udevTest(char *sysPath)
23{
24    const char *devPath;
25
26    struct udev_device *udev_device;
27    struct udev        *udev;
28
29    udev = udev_new();
30
31    if(udev == NULL)
32    {
33        printf("udev_new() failed, no access to udev system?\n");
34        return(1);
35    }
36
37    udev_device = udev_device_new_from_syspath(udev, sysPath);
38
39    if (udev_device == NULL)
40    {
41        printf("udev_device_new_from_syspath(%s) failed\n", sysPath);
42        return(2);
43    }
44
45    devPath = udev_device_get_devnode(udev_device);
46
47    udev_unref(udev);
48
49    if (devPath == NULL)
50    {
51        printf("udev_device_get_devnode() failed\n");
52        return(3);
53    }
54
55    printf("%s is known as %s\n", sysPath, devPath);
56
57    return(0);
58}