166194130SHans Petter Selasky /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 35e53a4f9SPedro F. Giffuni * 466194130SHans Petter Selasky * Copyright (c) 2013 Hans Petter Selasky. All rights reserved. 566194130SHans Petter Selasky * 666194130SHans Petter Selasky * Redistribution and use in source and binary forms, with or without 766194130SHans Petter Selasky * modification, are permitted provided that the following conditions 866194130SHans Petter Selasky * are met: 966194130SHans Petter Selasky * 1. Redistributions of source code must retain the above copyright 1066194130SHans Petter Selasky * notice, this list of conditions and the following disclaimer. 1166194130SHans Petter Selasky * 2. Redistributions in binary form must reproduce the above copyright 1266194130SHans Petter Selasky * notice, this list of conditions and the following disclaimer in the 1366194130SHans Petter Selasky * documentation and/or other materials provided with the distribution. 1466194130SHans Petter Selasky * 1566194130SHans Petter Selasky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1666194130SHans Petter Selasky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1766194130SHans Petter Selasky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1866194130SHans Petter Selasky * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1966194130SHans Petter Selasky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2066194130SHans Petter Selasky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2166194130SHans Petter Selasky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2266194130SHans Petter Selasky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2366194130SHans Petter Selasky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2466194130SHans Petter Selasky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2566194130SHans Petter Selasky * SUCH DAMAGE. 2666194130SHans Petter Selasky */ 2766194130SHans Petter Selasky 2866194130SHans Petter Selasky #ifndef _LIBUSB_GLOBAL_LINUX_H_ 2966194130SHans Petter Selasky #define _LIBUSB_GLOBAL_LINUX_H_ 3066194130SHans Petter Selasky 3166194130SHans Petter Selasky #define _XOPEN_SOURCE 3266194130SHans Petter Selasky #define _BSD_SOURCE 3399cd1f32SHans Petter Selasky #ifdef __linux__ 3466194130SHans Petter Selasky #define _POSIX_SOURCE 3599cd1f32SHans Petter Selasky #endif 3666194130SHans Petter Selasky #define _POSIX_C_SOURCE 200809 3766194130SHans Petter Selasky 3866194130SHans Petter Selasky #include <ctype.h> 3966194130SHans Petter Selasky #include <errno.h> 4066194130SHans Petter Selasky #include <stdio.h> 4166194130SHans Petter Selasky #include <stdlib.h> 4266194130SHans Petter Selasky #include <stdint.h> 4366194130SHans Petter Selasky #include <time.h> 4466194130SHans Petter Selasky #include <unistd.h> 4599cd1f32SHans Petter Selasky #ifdef __linux__ 4666194130SHans Petter Selasky #include <alloca.h> 4799cd1f32SHans Petter Selasky #endif 4866194130SHans Petter Selasky #include <string.h> 4966194130SHans Petter Selasky #include <fcntl.h> 5066194130SHans Petter Selasky #include <limits.h> 5199cd1f32SHans Petter Selasky #include <setjmp.h> 52d94d94e2SHans Petter Selasky #include <signal.h> 5366194130SHans Petter Selasky #include <pthread.h> 5466194130SHans Petter Selasky #include <sys/queue.h> 5566194130SHans Petter Selasky #include <sys/ioctl.h> 5666194130SHans Petter Selasky #include <sys/poll.h> 5766194130SHans Petter Selasky #include <sys/time.h> 5866194130SHans Petter Selasky #include <dev/usb/usb_endian.h> 5966194130SHans Petter Selasky #include <dev/usb/usb_freebsd.h> 6066194130SHans Petter Selasky 6199cd1f32SHans Petter Selasky #include <compat/linux/linux_ioctl.h> 6299cd1f32SHans Petter Selasky 6399cd1f32SHans Petter Selasky #define IOUSB(a) FBSD_L##a 6499cd1f32SHans Petter Selasky 6566194130SHans Petter Selasky #ifndef __aligned 6666194130SHans Petter Selasky #define __aligned(x) __attribute__((__aligned__(x))) 6766194130SHans Petter Selasky #endif 6866194130SHans Petter Selasky 6966194130SHans Petter Selasky #ifndef __packed 7066194130SHans Petter Selasky #define __packed __attribute__((__packed__)) 7166194130SHans Petter Selasky #endif 7266194130SHans Petter Selasky 7366194130SHans Petter Selasky #ifndef strlcpy 7466194130SHans Petter Selasky #define strlcpy(d,s,len) do { \ 7566194130SHans Petter Selasky strncpy(d,s,len); \ 7666194130SHans Petter Selasky ((char *)d)[(len) - 1] = 0; \ 7766194130SHans Petter Selasky } while (0) 7866194130SHans Petter Selasky #endif 7966194130SHans Petter Selasky 80f6428705SHans Petter Selasky #ifndef TAILQ_FOREACH_SAFE 81f6428705SHans Petter Selasky #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ 82f6428705SHans Petter Selasky for ((var) = TAILQ_FIRST((head)); \ 83f6428705SHans Petter Selasky (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ 84f6428705SHans Petter Selasky (var) = (tvar)) 85f6428705SHans Petter Selasky #endif 86f6428705SHans Petter Selasky 8766194130SHans Petter Selasky #endif /* _LIBUSB_GLOBAL_LINUX_H_ */ 88