Re: lsusb.c relies on Linux-specific byte-swap call
Joe Peterson <[email protected]>
| Newsgroups | gmane.linux.usb.devel |
|---|---|
| Message-ID | <[email protected]> |
Xiaofan Chen wrote: > On 11/1/07, Joe Peterson <[email protected]> wrote: >> Hi all, >> >> I am a developer at Gentoo, and I work on a subproject that uses the >> FreeBSD kernel. >> >> The latest version of usbutils in Gentoo (0.73) uses the call: >> __le16_to_cpu (in asm/byteorder.h). This is not in FreeBSD, so it does >> not build on the fbsd port. I have patched it to work, but it might be >> good to get this compatibility fix upstream. Let me know if I should >> contact the devel list instead. >> >> Thanks, Joe >> >> Here is the patch: >> >> --- usbutils-0.73/lsusb.c.old 2007-10-23 15:04:32 -0600 >> +++ usbutils-0.73/lsusb.c 2007-10-31 13:50:37 -0600 >> @@ -35,8 +35,17 @@ >> #include <errno.h> >> #include <stdio.h> >> #include <stdarg.h> >> +#ifdef __FreeBSD__ >> +#include <machine/endian.h> >> +#if _BYTE_ORDER == _LITTLE_ENDIAN >> +#define le16_to_cpu(x) (x) >> +#else >> +#define le16_to_cpu __bswap16 >> +#endif >> +#else >> #include <asm/byteorder.h> >> #define le16_to_cpu __le16_to_cpu >> +#endif >> #include <usb.h> >> > > Thanks for the patch. I've always wanted to look for such a utility under > FreeBSD and I do not know that usbutils work under FreeBSD. The > function is a bit different though since hubs are not found. Hi Xiaofan, Well, we still need to do some testing, but at least the patch gets past the byte order issue in the compile. BTW, attached is a new patch, which fixes the problem in configure.in, thereby making use of autotools rather than hard-coding the arch ifdef in the code: -Joe ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ [email protected] To unsubscribe, use the last form field at: https://lists.sourceforge.net/lists/listinfo/linux-usb-devel
usbutils-0.73-byteorder.patch
(text/plain, 1.1 KB)
diff -Nur usbutils-0.73.old/configure.in usbutils-0.73/configure.in --- usbutils-0.73.old/configure.in 2007-10-23 15:19:32 -0600 +++ usbutils-0.73/configure.in 2007-11-01 09:17:48 -0600 @@ -20,7 +20,7 @@ AC_FUNC_ALLOCA AC_HEADER_DIRENT AC_HEADER_STDC -AC_CHECK_HEADERS([fcntl.h stdlib.h string.h sys/ioctl.h sys/param.h unistd.h getopt.h errno.h ]) +AC_CHECK_HEADERS([fcntl.h stdlib.h string.h sys/ioctl.h sys/param.h unistd.h getopt.h errno.h asm/byteorder.h machine/endian.h]) # Checks for typedefs, structures, and compiler characteristics. AC_C_CONST diff -Nur usbutils-0.73.old/lsusb.c usbutils-0.73/lsusb.c --- usbutils-0.73.old/lsusb.c 2007-10-23 15:04:32 -0600 +++ usbutils-0.73/lsusb.c 2007-11-01 09:19:04 -0600 @@ -35,8 +35,17 @@ #include <errno.h> #include <stdio.h> #include <stdarg.h> +#if defined(HAVE_ASM_BYTEORDER_H) #include <asm/byteorder.h> #define le16_to_cpu __le16_to_cpu +#elif defined(HAVE_MACHINE_ENDIAN_H) +#include <machine/endian.h> +#if _BYTE_ORDER == _LITTLE_ENDIAN +#define le16_to_cpu(x) (x) +#else +#define le16_to_cpu __bswap16 +#endif +#endif #include <usb.h> /* NOTE: that should be <libusb.h> and it should include