最終更新:2017-06-13 (火) 16:23:06 (2499d)  

find_usbfs_path
Top / find_usbfs_path

処理

コード

  • static const char *find_usbfs_path(void)
    {
    	const char *path = "/dev/bus/usb";
    	const char *ret = NULL;
    
    	if (check_usb_vfs(path)) {
    		ret = path;
    	} else {
    		path = "/proc/bus/usb";
    		if (check_usb_vfs(path))
    			ret = path;
    	}
    
    	/* look for /dev/usbdev*.* if the normal places fail */
    	if (ret == NULL) {
    		struct dirent *entry;
    		DIR *dir;
    
    		path = "/dev";
    		dir = opendir(path);
    		if (dir != NULL) {
    			while ((entry = readdir(dir)) != NULL) {
    				if (_is_usbdev_entry(entry, NULL, NULL)) {
    					/* found one; that's enough */
    					ret = path;
    					usbdev_names = 1;
    					break;
    				}
    			}
    			closedir(dir);
    		}
    	}
    
    /* On udev based systems without any usb-devices /dev/bus/usb will not
     * exist. So if we've not found anything and we're using udev for hotplug
     * simply assume /dev/bus/usb rather then making libusb_init fail. */
    #if defined(USE_UDEV)
    	if (ret == NULL)
    		ret = "/dev/bus/usb";
    #endif
    
    	if (ret != NULL)
    		usbi_dbg("found usbfs at %s", ret);
    
    	return ret;
    }