1.\" 2.\" Copyright (c) 2025 Rick Parrish <unitrunker@unitrunker.net> 3.\" 4.\" SPDX-License-Identifier: BSD-2-Clause 5.\" 6.Dd December 14, 2025 7.Dt LIBUSB20 3 8.Os 9.Sh NAME 10.Nm libusb20_be_device_foreach 11.Nd iterate connected USB devices 12.Sh SYNOPSIS 13.Lb libusb 14.In libusb20.h 15.Ft struct libusb20_device * 16.Fn libusb20_be_device_foreach "struct libusb20_backend *pbe" "struct libusb20_device *pdev" 17.Sh DESCRIPTION 18The 19.Nm 20function iterates connected USB devices, one device at a time. 21A backend pointer for 22.Fa pbe 23may be obtained by calling 24.Xr libusb20_be_alloc_default 3 . 25The starting value of 26.Fa pdev 27is NULL. 28Calling 29.Nm libusb20_be_device_foreach 30again with 31.Fa pdev 32set to the return value of the previous call yields the next device. 33To begin interacting with a USB device, pass the pointer in a call to 34.Xr libusb20_dev_open 3 . 35.Sh RETURN VALUES 36.Nm 37returns NULL for end of list. 38Otherwise this is a pointer to the next device. 39.Sh EXAMPLES 40.Bd -literal 41 #include <libusb20.h> 42 struct libusb20_backend *be = libusb20_be_alloc_default(); 43 struct libusb20_device *device = NULL; 44 while ( (device = libusb20_be_device_foreach(be, device)) != NULL ) { 45 if (libusb20_dev_open(device, 0) == LIBUSB20_SUCCESS) { 46 /* do something */ 47 libusb20_dev_close(device); 48 } 49 } 50 libusb20_be_free(be); 51.Ed 52.Sh SEE ALSO 53.Xr libusb20 3 , 54.Xr libusb20_be_alloc_default 3 , 55.Xr libusb20_be_free 3 , 56.Xr libusb20_dev_open 3 57