From 0b8d7927213de8679fda3f58d460b754fe2f65f0 Mon Sep 17 00:00:00 2001 From: hselasky Date: Wed, 13 Mar 2013 12:23:14 +0000 Subject: [PATCH] - Make the FreeBSD's USB library compile under Linux. - Fix a compile warning where the return value of a call to a write() function was ignored. - Remove redundant include files from userland USB header files. - Add some now needed include files to various C-files. --- lib/libusb/Makefile | 13 ++++++ lib/libusb/libusb.h | 3 ++ lib/libusb/libusb01.c | 9 ++++- lib/libusb/libusb10.c | 16 +++++--- lib/libusb/libusb10.h | 2 + lib/libusb/libusb10_desc.c | 9 ++++- lib/libusb/libusb10_io.c | 9 ++++- lib/libusb/libusb20.c | 8 +++- lib/libusb/libusb20.h | 8 +--- lib/libusb/libusb20_desc.c | 8 +++- lib/libusb/libusb20_desc.h | 4 ++ lib/libusb/libusb20_ugen20.c | 18 +++++---- lib/libusb/libusb_global_linux.h | 69 ++++++++++++++++++++++++++++++++ lib/libusb/usb.h | 5 ++- usr.sbin/usbconfig/usbconfig.c | 1 + 15 files changed, 152 insertions(+), 30 deletions(-) create mode 100644 lib/libusb/libusb_global_linux.h diff --git a/lib/libusb/Makefile b/lib/libusb/Makefile index 9c2c9b45a87d..66dd7959caf4 100644 --- a/lib/libusb/Makefile +++ b/lib/libusb/Makefile @@ -37,6 +37,19 @@ SRCS+= libusb10_io.c CFLAGS+= -DCOMPAT_32BIT .endif +# +# Cross platform support +# +# Examples: +# make LIBUSB_GLOBAL_INCLUDE_FILE=libusb_global_linux.h +# make COMPAT_32BIT=YES LIBUSB_GLOBAL_INCLUDE_FILE=libusb_global_linux.h +# +.if defined(LIBUSB_GLOBAL_INCLUDE_FILE) +CFLAGS+= -DLIBUSB_GLOBAL_INCLUDE_FILE=\"${LIBUSB_GLOBAL_INCLUDE_FILE}\" +CFLAGS+= -DUSB_GLOBAL_INCLUDE_FILE=\"${LIBUSB_GLOBAL_INCLUDE_FILE}\" +CFLAGS+= -I ../../sys +.endif + .include # LibUSB v1.0 diff --git a/lib/libusb/libusb.h b/lib/libusb/libusb.h index 1675f469d845..225b539e907a 100644 --- a/lib/libusb/libusb.h +++ b/lib/libusb/libusb.h @@ -27,8 +27,11 @@ #ifndef __LIBUSB_H__ #define __LIBUSB_H__ +#ifndef LIBUSB_GLOBAL_INCLUDE_FILE +#include #include #include +#endif #ifdef __cplusplus extern "C" { diff --git a/lib/libusb/libusb01.c b/lib/libusb/libusb01.c index 17edb0e7df93..30a143001b29 100644 --- a/lib/libusb/libusb01.c +++ b/lib/libusb/libusb01.c @@ -28,11 +28,16 @@ * This file contains the emulation layer for LibUSB v0.1 from sourceforge. */ -#include - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include #include #include +#include +#include +#include +#endif #include "libusb20.h" #include "libusb20_desc.h" diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c index 256d67e93bc5..021229669119 100644 --- a/lib/libusb/libusb10.c +++ b/lib/libusb/libusb10.c @@ -25,17 +25,23 @@ * SUCH DAMAGE. */ -#include -#include -#include - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include #include #include #include #include #include +#include #include +#include +#include +#include +#include +#include +#endif #define libusb_device_handle libusb20_device @@ -1331,7 +1337,7 @@ libusb10_submit_transfer_sub(struct libusb20_device *pdev, uint8_t endpoint) /* make sure our event loop spins the done handler */ dummy = 0; - write(dev->ctx->ctrl_pipe[1], &dummy, sizeof(dummy)); + err = write(dev->ctx->ctrl_pipe[1], &dummy, sizeof(dummy)); } /* The following function must be called unlocked */ diff --git a/lib/libusb/libusb10.h b/lib/libusb/libusb10.h index d2a2bd7c150b..f1e5460a14be 100644 --- a/lib/libusb/libusb10.h +++ b/lib/libusb/libusb10.h @@ -27,7 +27,9 @@ #ifndef __LIBUSB10_H__ #define __LIBUSB10_H__ +#ifndef LIBUSB_GLOBAL_INCLUDE_FILE #include +#endif #define GET_CONTEXT(ctx) (((ctx) == NULL) ? usbi_default_context : (ctx)) #define UNEXPORTED __attribute__((__visibility__("hidden"))) diff --git a/lib/libusb/libusb10_desc.c b/lib/libusb/libusb10_desc.c index 11e201f37551..d2f3f5390109 100644 --- a/lib/libusb/libusb10_desc.c +++ b/lib/libusb/libusb10_desc.c @@ -24,10 +24,15 @@ * SUCH DAMAGE. */ -#include - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include #include +#include +#include +#include +#endif #define libusb_device_handle libusb20_device diff --git a/lib/libusb/libusb10_io.c b/lib/libusb/libusb10_io.c index 302fdb8dda32..489ceb76caed 100644 --- a/lib/libusb/libusb10_io.c +++ b/lib/libusb/libusb10_io.c @@ -24,15 +24,20 @@ * SUCH DAMAGE. */ -#include - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include #include #include #include #include +#include #include #include +#include +#include +#endif #define libusb_device_handle libusb20_device diff --git a/lib/libusb/libusb20.c b/lib/libusb/libusb20.c index ce7551131d10..644eda4f5498 100644 --- a/lib/libusb/libusb20.c +++ b/lib/libusb/libusb20.c @@ -24,13 +24,17 @@ * SUCH DAMAGE. */ -#include - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include #include #include #include #include +#include +#include +#endif #include "libusb20.h" #include "libusb20_desc.h" diff --git a/lib/libusb/libusb20.h b/lib/libusb/libusb20.h index 81928b143466..4a57b49710f6 100644 --- a/lib/libusb/libusb20.h +++ b/lib/libusb/libusb20.h @@ -29,13 +29,9 @@ #ifndef _LIBUSB20_H_ #define _LIBUSB20_H_ -#include -#include -#include - +#ifndef LIBUSB_GLOBAL_INCLUDE_FILE #include -#include -#include +#endif #ifdef __cplusplus extern "C" { diff --git a/lib/libusb/libusb20_desc.c b/lib/libusb/libusb20_desc.c index e2fa5b55c95b..22077b61f160 100644 --- a/lib/libusb/libusb20_desc.c +++ b/lib/libusb/libusb20_desc.c @@ -24,11 +24,15 @@ * SUCH DAMAGE. */ -#include - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include #include #include +#include +#include +#endif #include "libusb20.h" #include "libusb20_desc.h" diff --git a/lib/libusb/libusb20_desc.h b/lib/libusb/libusb20_desc.h index a069ee96a68b..48e2715d2003 100644 --- a/lib/libusb/libusb20_desc.h +++ b/lib/libusb/libusb20_desc.h @@ -45,6 +45,10 @@ #ifndef _LIBUSB20_DESC_H_ #define _LIBUSB20_DESC_H_ +#ifndef LIBUSB_GLOBAL_INCLUDE_FILE +#include +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/lib/libusb/libusb20_ugen20.c b/lib/libusb/libusb20_ugen20.c index bff8e02e7c26..0846eb4b7d52 100644 --- a/lib/libusb/libusb20_ugen20.c +++ b/lib/libusb/libusb20_ugen20.c @@ -24,24 +24,28 @@ * SUCH DAMAGE. */ -#include -#include - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include #include #include #include #include #include - -#include "libusb20.h" -#include "libusb20_desc.h" -#include "libusb20_int.h" +#include +#include +#include +#endif #include #include #include +#include "libusb20.h" +#include "libusb20_desc.h" +#include "libusb20_int.h" + static libusb20_init_backend_t ugen20_init_backend; static libusb20_open_device_t ugen20_open_device; static libusb20_close_device_t ugen20_close_device; diff --git a/lib/libusb/libusb_global_linux.h b/lib/libusb/libusb_global_linux.h new file mode 100644 index 000000000000..cbdd2c6b818d --- /dev/null +++ b/lib/libusb/libusb_global_linux.h @@ -0,0 +1,69 @@ +/* $FreeBSD$ */ +/*- + * Copyright (c) 2013 Hans Petter Selasky. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _LIBUSB_GLOBAL_LINUX_H_ +#define _LIBUSB_GLOBAL_LINUX_H_ + +#define _XOPEN_SOURCE +#define _BSD_SOURCE +#define _POSIX_SOURCE +#define _POSIX_C_SOURCE 200809 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef __aligned +#define __aligned(x) __attribute__((__aligned__(x))) +#endif + +#ifndef __packed +#define __packed __attribute__((__packed__)) +#endif + +#ifndef strlcpy +#define strlcpy(d,s,len) do { \ + strncpy(d,s,len); \ + ((char *)d)[(len) - 1] = 0; \ +} while (0) +#endif + +#endif /* _LIBUSB_GLOBAL_LINUX_H_ */ diff --git a/lib/libusb/usb.h b/lib/libusb/usb.h index dc3959e17f81..d7bbaa558279 100644 --- a/lib/libusb/usb.h +++ b/lib/libusb/usb.h @@ -27,10 +27,11 @@ #ifndef _LIBUSB20_COMPAT_01_H_ #define _LIBUSB20_COMPAT_01_H_ +#ifndef LIBUSB_GLOBAL_INCLUDE_FILE +#include #include #include - -#include +#endif /* USB interface class codes */ diff --git a/usr.sbin/usbconfig/usbconfig.c b/usr.sbin/usbconfig/usbconfig.c index a1fa694b2aaf..c046003a636a 100644 --- a/usr.sbin/usbconfig/usbconfig.c +++ b/usr.sbin/usbconfig/usbconfig.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include