summaryrefslogtreecommitdiff
path: root/examples
Commit message (Collapse)AuthorAgeFilesLines
* examples: Replace most uses of sprintf with safer snprintfSean McBride2022-06-261-1/+1
| | | | Closes #1155
* examples: Do not assume positive errno macrosTormod Volden2022-01-223-14/+37
| | | | | | | | | | | | | | Some functions were returning e.g. -ENOMEM and the caller would check for negative return values. However, on Haiku, contrary to modern standards, these macros are negative, so this logic would fail. In any case, change the function to return -1 instead. For good measure also set errno to the appropriate value, although it is not used in the current code. This was discovered on Haiku builds because the value for ENOMEM is INT_MIN which cannot be negated without overflow. Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* xusb: Print total length of configuration descriptorTormod Volden2021-10-311-0/+1
| | | | Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* Fix various typos in docs/commentsluz paz2021-10-312-3/+3
| | | | | | Found via `codespell -q 3` Closes #1015
* xusb: Print configuration descriptor lengthTormod Volden2021-10-311-1/+6
| | | | | | Also inform about reading OS string descriptor. Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
* xusb: add check for interface kernel driverNathan Hjelm2021-07-211-0/+2
| | | | | | | This commit adds a call to libusb_kernel_driver_active and prints out the result. This provides a way to quickly check the result when testing. Signed-off-by: Nathan Hjelm <hjelmn@google.com>
* Windows: Support building dpfp and sam3u_benchmark with MSVCChris Dickens2020-11-271-0/+4
| | | | | | Closes #151 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* build: Prepare config.h for inclusion in examples/testsChris Dickens2020-11-273-12/+8
| | | | | | | | | | | | There are certain games played in the examples and tests source to account for differences in build environments and target platforms. This can be simplified by including config.h and using the definitions there. To that end, move the printf function attribute definition from libusbi.h to config.h and leverage it where it is used in the examples and tests. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* build: Fix Android and Xcode compilation errors/warningsChris Dickens2020-11-162-25/+33
| | | | | | | | | | | | | | | | | | Commit f69548c3b3 ("examples: Enable all examples to build on all platforms") modified dpfp and sam3u_benchmark to be buildable on any platform, however there were some oversights and regressions introduced for Android and Xcode. Update the Android and Xcode build files to account for the removal of dpfp_threaded.c as well as the inclusion of config.h from examples and/or tests source. Additionally switch the threaded version of dpfp to use sem_open() instead of sem_init() as the latter is in fact deprecated on MacOS. Closes #808 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* examples: Enable all examples to build on all platformsChris Dickens2020-11-105-648/+298
| | | | | | | | | | | | | | | | Prior to this change, the dpfp and sam3u_benchmark examples were only built on POSIX platforms due to a dependency on sigaction(). Furthermore the dpfp_threaded example only worked with POSIX threads. Lift this limitation by breaking the dependence on sigaction(). Also provide a minimal threading abstraction so that dpfp_threaded can be built on Windows as well. Also merge the sources for dpfp and dpfp_threaded. The only difference between the two is how libusb's event handling functions are called and this can be easily handled within a single source file. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Fix various CI build warningsChris Dickens2020-11-091-0/+1
| | | | | | | | | | | | * [-Wpointer-arith] arithmetic on a pointer to void is a GNU extension * [-Wswitch-enum] enumeration values 'E1, ...' not explicitly handled in switch * [-Wunused-parameter] unused parameter 'p' For '-Wswitch-enum', the switch statements in the individual backends' set_option() function has been removed. It is not expected that backends will need to handle or be aware of all the options. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* examples/testlibusb: Print speed of devicesHans de Goede2020-09-141-2/+12
| | | | | | Print the speed of devices to exercise libusb_get_device_speed(). Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* examples/testlibusb: Add support for testing libusb_wrap_sys_device()Hans de Goede2020-09-141-13/+64
| | | | | | | Sometimes it is useful to be able to test libusb_wrap_sys_device(), add support for this to the testlibusb example Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* build: Merge events and threads into single platform abstractionChris Dickens2020-09-121-1/+1
| | | | | | | | | | | | | | The split between events and threads abstractions is unnecessary. Simplify the library by merging the two into a "platform" abstraction. The only meaningful change is that Cygwin builds will no longer use the POSIX threads abstraction but will instead use the native Windows one. The downside to doing this is that the dpfp_threaded example program will no longer be available on Cygwin builds. This should be fine, and future work will make dpfp_threaded available for all forms of Windows build systems. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Fix typos detected by codespell and manual inspectionChris Dickens2020-08-182-2/+2
| | | | Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* configure.ac: Simplify detection of Windows compilationChris Dickens2020-04-091-2/+2
| | | | | | | | | | | | There are a few parts within the library where code is conditionally compiled based on whether or not the target OS is Windows. Prior to commit 8b09dd490d ("core: Kill the OS_* definitions and use in the source code"), the OS_WINDOWS definition was used. With that definition gone, the checks were replaced with _WIN32. Unfortunately the different cross-platform toolchains do not universally define this, so add this to AM_CPPFLAGS when building for Windows. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Xcode: Update project fileChris Dickens2020-03-301-6/+6
| | | | | | | | | | | | | | | | | Add '-fvisibility=hidden' to the additional compiler flags of the libusb target so that internal library symbols are hidden. Add '-pthread' to the additional compiler flags of the targets that directly use pthread functionality Add the 'sam3u_benchmark' and 'testlibusb' targets so that all examples are now built and fix build warnings that occur when building 'sam3u_benchmark'. Fix target dependencies so that all targets are able to build without issues. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* build: Enable additional build errors and warningsChris Dickens2020-03-302-2/+3
| | | | | | | | | | | Help catch more errors by enabling additional build errors and warnings. Address some of the warnings seen with these new flags, including moving the libusb_transfer structure back out of the usbi_transfer structure to address 'warning: invalid use of structure with flexible array member'. Apparently a structure ending with a flexible array member is not okay with the compiler as the last member within another structure. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* build: Require C11 to build and clean up autoconfig/automake filesChris Dickens2020-03-302-11/+10
| | | | | | | | | | | | | | | | | | | | | | | C11 compiler support has been available for many years now. It is not unreasonable to require this now, and doing so allows some cleanup to the configure script. It is no longer necessary to check for compiler support of the '-fvibility' flag because any compiler that supports C11 will support this flag as well. Fix up the way that compiler and linker flags are passed down to the various makefiles. The compiler flags should be shared by all, but the linker flags and libraries should be separated between the library and the examples/tests. The visibility flag is only relevant for the library and the thread flags are only relevant for sources using thread constructs, so provide them as needed. Rearrange configure.ac to group similar functionality and consolidate where possible. Based on these changes, update the Travis configuration file to include newer versions of test platforms to ensure proper C11 compiler support. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* msvc: Reorder solution projects and add project filter filesChris Dickens2020-03-233-1428/+0
| | | | | | | | | | | | | | Since Visual Studio picks the first project as the default startup project, move the library projects back to the top of the list. This use to be the order but was changed in commit 9843b689df. Add the project filter files to help organize the source files within the Solution Explorer window pane. Additionally move the getopt source underneath the msvc directory since it is only used for Visual Studio builds. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Windows: Remove support for WinCE and Visual Studio older than 2013Chris Dickens2020-01-203-35/+18
| | | | | | | | | | | There appears to be no need for the WinCE backend anymore, and it is increasingly difficult to keep healthy as the rest of the library changes. Require at least Visual Studio 2013 to compile. This simplifies matters as there is some semblance of C99 support there. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* examples: testlibusb: Always print VID and PID in addition to stringsChris Dickens2020-01-131-26/+15
| | | | | | | | | | | Previously the program would only print the VID when the manufacturer string is unavailable and the PID when the product string is unavailable. Change this to print the VID and PID unconditionally and print the manufacturer and product strings similar to how the serial number string is being printed. In addition, line up the string values with the rest of the output. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* examples: testlibusb: Formatting, whitespace and functional cleanupChris Dickens2020-01-131-96/+83
| | | | | | | | | | | | | | | | | | | | | Make the coding style and whitespace consistent with the rest of the library source code. In the print_device() function, the 'level' argument is unnecessary, so remove it and the associated space padding. Switch to use printf() directly instead of formatting the description into a single buffer. This not only simplifies the code but avoids truncating the description for devices with larger descriptor strings. Make the output formatting consistent by lining up all the printed values and using the same notation for all hexadecimal values. Inspired by PR #452, enable printing all available BOS device capability descriptors, not just the first one. Closes #452 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* xusb: Report SuperSpeedPlusHarry Mallon2019-04-041-3/+3
| | | | | | Closes #530 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Fixed many compiler warnings about sign and size mismatchSean McBride2019-01-303-4/+4
| | | | | | | | | | - added various casts - added some asserts where the casts made assumptions - enabled additional warnings in Xcode project (especially -Wshorten-64-to-32) Closes #509 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* examples: Fix format-truncation on debugVictor Toso2018-12-051-1/+1
| | | | | | | | | | | | | | | | | | | | As description is used only for debug, we can extend it to be sure to fit 256 from string variable plus 3 chars from " - " as described in gcc warning below | testlibusb.c: In function ‘print_device.constprop’: | testlibusb.c:188:51: warning: ‘ - ’ directive output may be truncated writing 3 bytes into a region of size between 1 and 256 [-Wformat-truncation=] | snprintf(description, sizeof(description), "%s - ", string); | ^~~ | testlibusb.c:188:5: note: ‘snprintf’ output between 4 and 259 bytes into a destination of size 256 | snprintf(description, sizeof(description), "%s - ", string); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Closes #460 Signed-off-by: Victor Toso <victortoso@redhat.com> Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
* Add missing libusb_exit on an error conditiongudenau2018-12-051-1/+3
| | | | | | Closes #448 Signed-off-by: Nathan Hjelm <hjelmn@lanl.gov>
* examples: testlibusb: Fix DDK build warningChris Dickens2018-03-241-3/+4
| | | | Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Fixed various trivial cppcheck 1.80 warningsSean McBride2017-12-282-2/+2
| | | | | | | | | | | | | | | | | Specifically: redundantAssignment,examples/dpfp.c:422,style,Variable 'r' is reassigned a value before the old one has been used. redundantAssignment,libusb/os/threads_posix.c:64,style,Variable 'ret' is reassigned a value before the old one has been used. unreadVariable,libusb/os/netbsd_usb.c:217,style,Variable 'hpriv' is assigned a value that is never used. unreadVariable,libusb/os/netbsd_usb.c:235,style,Variable 'hpriv' is assigned a value that is never used. unreadVariable,libusb/os/openbsd_usb.c:251,style,Variable 'hpriv' is assigned a value that is never used. unreadVariable,libusb/os/openbsd_usb.c:275,style,Variable 'hpriv' is assigned a value that is never used. unsignedLessThanZero,libusb/os/windows_winusb.c:259,style,Checking if unsigned variable '_index' is less than zero. unsignedLessThanZero,libusb/os/windows_winusb.c:298,style,Checking if unsigned variable '_index' is less than zero. unsignedLessThanZero,libusb/os/windows_winusb.c:367,style,Checking if unsigned variable '_index' is less than zero. invalidPrintfArgType_sint,examples/xusb.c:534,warning,%d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* examples: xusb: replaced insecure sprintf with snprintfSean McBride2017-12-281-1/+2
| | | | Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Fix unused parameter warningsSean McBride2017-12-283-0/+16
| | | | Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* examples: ezusb: Renamed header guard variable to not use reserved identifierSean McBride2017-12-281-2/+2
| | | | | | Fixes clang -Wreserved-id-macro warning. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Misc: Fix testlibusb build on VS2013 and earlier and suppress warningsChris Dickens2017-12-261-0/+4
| | | | Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Examples: Misc. cleanup to xusbChris Dickens2017-12-261-9/+6
| | | | | | | Make data that is unchanged const, remove an unused return value, and add a missing newline to an error message. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* Examples: Improvements to xusb's support for Microsoft OS descriptorsChris Dickens2017-12-261-5/+14
| | | | | | | | | | | | | As noted in issue #269, the current xusb implementation does not handle Microsoft OS descriptors from devices whose vendor code is greater than 0x7F. This commit addresses this limitation by using libusb_get_string_descriptor() instead of the ASCII variant and parsing the descriptor separately. Note that this issue was addressed in PR #276, but that approach was too cryptic to read. Closes #269, Closes #276 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* examples: Fix device handle leak in xusbChris Dickens2017-08-241-12/+10
| | | | | | | | | | | | The CALL_CHECK macro returns from the current function, so in the test_device() function the device handle was being leaked when one of the functions failed. This commit adds a new CALL_CHECK_CLOSE macro that does the same as CALL_CHECK but also closes the device handle before returning. In addition, the macros are changed to declare their needed variable rather than relying on the variable to already exist within the scope of the function. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* core: Introduce libusb_set_option() API functionChris Dickens2017-07-162-3/+3
| | | | | | | | | | | | | | This new function allows more flexibility in extending the library to support more user-configurable options. It is intended to provide a single API that can support a wide variety of needs and eliminates the need for new API functions to set future options. The function is introduced with a single option (LIBUSB_OPTION_LOG_LEVEL) that replaces the libusb_set_debug() function. Documentation relating to libusb_set_debug() and the uses of this function in the examples and tests have been updated accordingly. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* examples: reformat testlibusb.cLudovic Rousseau2017-07-121-273/+272
| | | | | convert from DOS to Unix text format remove extra spaces at end of line
* examples: add missing include to dpfp_threadedNathan Hjelm2016-07-211-0/+1
| | | | Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* examples: make dpfp_threaded work on OS XNathan Hjelm2016-07-211-7/+10
| | | | | | | OS X does not support unnamed semaphores so the example has been updated to use a named semaphore instead. Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Examples: Ported testlibusb from libus-0.1 to libusb-1.0Anil Nair2016-07-212-1/+274
| | | | | | | | | This commit is based on Nathan's branch https://github.com/hjelmn/libusb-darwin/blob/master/examples/testlibusb1.c Closes #178 Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* examples: fix 3 compiler warningsLudovic Rousseau2016-03-061-3/+3
| | | | | | | | | | | | examples/hotplugtest.c:76:28: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32] vendor_id = (argc > 1) ? strtol (argv[1], NULL, 0) : 0x045a; ~ ^~~~~~~~~~~~~~~~~~~~~~~~~ examples/hotplugtest.c:77:28: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32] product_id = (argc > 2) ? strtol (argv[2], NULL, 0) : 0x5005; ~ ^~~~~~~~~~~~~~~~~~~~~~~~~ examples/hotplugtest.c:78:28: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32] class_id = (argc > 3) ? strtol (argv[3], NULL, 0) : LIBUSB_HOTPLUG_MATCH_ANY; ~ ^~~~~~~~~~~~~~~~~~~~~~~~~
* xusb: fix typoNathan Hjelm2016-03-051-1/+1
| | | | Signed-off-by: Nathan Hjelm <hjelmn@me.com>
* Replace obsolete usleep with nanosleepStefan Tauner2016-03-051-2/+2
| | | | | | | | This fixes compiling libusb with uclibc. Closes #141, #165 Signed-off-by: Stefan Tauner <stefan.tauner@gmx.at>
* examples: fix 3 compiler warningsLudovic Rousseau2016-03-021-1/+2
| | | | | | | | | | | | | | | | | fxload.c:202:17: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare] ...for (j=0; j<ARRAYSIZE(known_device); j++) { ~^~~~~~~~~~~~~~~~~~~~~~~~ fxload.c:222:12: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare] if (j < ARRAYSIZE(known_device)) { ~ ^ ~~~~~~~~~~~~~~~~~~~~~~~ fxload.c:263:13: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare] for (i=0; i<ARRAYSIZE(path); i++) { ~^~~~~~~~~~~~~~~~ Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
* examples: fix 2 compiler warningsLudovic Rousseau2016-03-021-1/+1
| | | | | | | | | | | | | sam3u_benchmark.c:54:17: warning: comparison of integers of different signs: 'unsigned int' and 'int' [-Wsign-compare] for (i = 0; i < xfr->num_iso_packets; i++) { ~ ^ ~~~~~~~~~~~~~~~~~~~~ sam3u_benchmark.c:67:16: warning: comparison of integers of different signs: 'unsigned int' and 'int' [-Wsign-compare] for (i = 0; i < xfr->actual_length; i++) { ~ ^ ~~~~~~~~~~~~~~~~~~ Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
* examples: fix 2 compiler warningsLudovic Rousseau2016-03-021-2/+2
| | | | | | | | | | | | | ezusb.c:136:13: warning: comparison of integers of different signs: 'int' and 'size_t' (aka 'unsigned long') [-Wsign-compare] if (status != len) { ~~~~~~ ^ ~~~ ezusb.c:159:13: warning: comparison of integers of different signs: 'int' and 'size_t' (aka 'unsigned long') [-Wsign-compare] if (status != len) { ~~~~~~ ^ ~~~ Signed-off-by: Ludovic Rousseau <ludovic.rousseau@free.fr>
* Examples: fix typo in Nathan Hjelm emailLudovic Rousseau2016-01-061-1/+1
|
* Examples: fxload improvementsChris Dickens2015-08-041-7/+28
| | | | | | | | * Add two-stage load support * Fix leaks in error-handling paths * Closes #12 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
* examples: Address issues reported by Markus ElfringChris Dickens2015-04-281-10/+15
| | | | | | | | | * Use sig_atomic_t as data type for variable do_exit * Use async-safe function within signal handler Closes #34 Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>