summaryrefslogtreecommitdiffstats
path: root/src/libusb1-test.c
blob: db381d86fd105991fddf2d862a6d7185c60cfe31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
 * This file is part of MXE. See LICENSE.md for licensing information.
 */

#include <stdio.h>
#include <libusb.h>

int main(int argc, char *argv[])
{
    int ret;
    ssize_t num_devs;
    libusb_context *ctx;
    libusb_device **devs;

    (void)argc;
    (void)argv;

    ret = libusb_init(&ctx);
    if (ret != LIBUSB_SUCCESS) {
        printf("Initialization error: %s.\n", libusb_error_name(ret));
        return 1;
    }

    num_devs = libusb_get_device_list(ctx, &devs);
    if (num_devs < 0 || !devs) {
        printf("Device list error: %s.\n", libusb_error_name(num_devs));
        return 2;
    }

    printf("Found %d USB devices.\n", (int)num_devs);

    libusb_free_device_list(devs, 1);

    libusb_exit(ctx);

    return 0;
}