-static int get_id_attr(
- struct udev_device *parent,
- const char *name,
- uint16_t *value) {
-
- const char *t;
- unsigned u;
-
- if (!(t = udev_device_get_sysattr_value(parent, name))) {
- fprintf(stderr, "%s lacks %s.\n", udev_device_get_syspath(parent), name);
- return -1;
- }
-
- if (startswith(t, "0x"))
- t += 2;
-
- if (sscanf(t, "%04x", &u) != 1 || u > 0xFFFFU) {
- fprintf(stderr, "Failed to parse %s on %s.\n", name, udev_device_get_syspath(parent));
- return -1;
- }
-
- *value = (uint16_t) u;
- return 0;
-}
-
-static int get_vid_pid(
- struct udev_device *parent,
- const char *vendor_attr,
- const char *product_attr,
- uint16_t *vid,
- uint16_t *pid) {
-
- if (get_id_attr(parent, vendor_attr, vid) < 0)
- return -1;
- else if (*vid <= 0) {
- fprintf(stderr, "Invalid vendor id.\n");
- return -1;
- }
-
- if (get_id_attr(parent, product_attr, pid) < 0)
- return -1;
-
- return 0;
-}
-
-static void rstrip(char *n) {
- size_t i;
-
- for (i = strlen(n); i > 0 && isspace(n[i-1]); i--)
- n[i-1] = 0;
-}