-#ifdef __linux__
- const gchar *usb_dev;
- const char device_tree[] = "/sys/bus/usb/devices/";
- GDir *devices_dir, *device_dir;
- GSList *l = NULL;
- GSList *tty_devs;
- GSList *matched_paths;
- FILE *fd;
- char tmp[5];
- gchar *vendor_path, *product_path, *path_copy;
- gchar *prefix, *subdir_path, *device_path, *tty_path;
- unsigned long read_vendor_id, read_product_id;
- const char *file;
-
- l = NULL;
- tty_devs = NULL;
- matched_paths = NULL;
-
- if (!(devices_dir = g_dir_open(device_tree, 0, NULL)))
- return NULL;
-
- /*
- * 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);