- /*
- * Find potential candidates using the vendor ID and product ID
- * and store them in matched_paths.
- */
- while ((usb_dev = g_dir_read_name(devices_dir))) {
- vendor_path = g_strconcat(device_tree,
- usb_dev, "/idVendor", NULL);
- product_path = g_strconcat(device_tree,
- usb_dev, "/idProduct", NULL);
-
- if (!g_file_test(vendor_path, G_FILE_TEST_EXISTS) ||
- !g_file_test(product_path, G_FILE_TEST_EXISTS))
- goto skip_device;
-
- if ((fd = g_fopen(vendor_path, "r")) == NULL)
- goto skip_device;
-
- if (fgets(tmp, sizeof(tmp), fd) == NULL) {
- fclose(fd);
- goto skip_device;
- }
- read_vendor_id = strtoul(tmp, NULL, 16);
-
- fclose(fd);
-
- if ((fd = g_fopen(product_path, "r")) == NULL)
- goto skip_device;
-
- if (fgets(tmp, sizeof(tmp), fd) == NULL) {
- fclose(fd);
- goto skip_device;
- }
- read_product_id = strtoul(tmp, NULL, 16);
-
- fclose(fd);
-
- if (vendor_id == read_vendor_id &&
- product_id == read_product_id) {
- path_copy = g_strdup(usb_dev);
- matched_paths = g_slist_prepend(matched_paths,
- path_copy);
- }