1248236Shselasky/* $FreeBSD: stable/11/lib/libusb/libusb_global_linux.h 358948 2020-03-13 09:17:51Z hselasky $ */
2248236Shselasky/*-
3248236Shselasky * Copyright (c) 2013 Hans Petter Selasky. All rights reserved.
4248236Shselasky *
5248236Shselasky * Redistribution and use in source and binary forms, with or without
6248236Shselasky * modification, are permitted provided that the following conditions
7248236Shselasky * are met:
8248236Shselasky * 1. Redistributions of source code must retain the above copyright
9248236Shselasky *    notice, this list of conditions and the following disclaimer.
10248236Shselasky * 2. Redistributions in binary form must reproduce the above copyright
11248236Shselasky *    notice, this list of conditions and the following disclaimer in the
12248236Shselasky *    documentation and/or other materials provided with the distribution.
13248236Shselasky *
14248236Shselasky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15248236Shselasky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16248236Shselasky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17248236Shselasky * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18248236Shselasky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19248236Shselasky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20248236Shselasky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21248236Shselasky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22248236Shselasky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23248236Shselasky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24248236Shselasky * SUCH DAMAGE.
25248236Shselasky */
26248236Shselasky
27248236Shselasky#ifndef _LIBUSB_GLOBAL_LINUX_H_
28248236Shselasky#define	_LIBUSB_GLOBAL_LINUX_H_
29248236Shselasky
30248236Shselasky#define	_XOPEN_SOURCE
31248236Shselasky#define	_BSD_SOURCE
32253339Shselasky#ifdef __linux__
33248236Shselasky#define	_POSIX_SOURCE
34253339Shselasky#endif
35248236Shselasky#define	_POSIX_C_SOURCE 200809
36248236Shselasky
37248236Shselasky#include <ctype.h>
38248236Shselasky#include <errno.h>
39248236Shselasky#include <stdio.h>
40248236Shselasky#include <stdlib.h>
41248236Shselasky#include <stdint.h>
42248236Shselasky#include <time.h>
43248236Shselasky#include <unistd.h>
44253339Shselasky#ifdef __linux__
45248236Shselasky#include <alloca.h>
46253339Shselasky#endif
47248236Shselasky#include <string.h>
48248236Shselasky#include <fcntl.h>
49248236Shselasky#include <limits.h>
50253339Shselasky#include <setjmp.h>
51248236Shselasky#include <pthread.h>
52248236Shselasky#include <sys/queue.h>
53248236Shselasky#include <sys/ioctl.h>
54248236Shselasky#include <sys/poll.h>
55248236Shselasky#include <sys/time.h>
56248236Shselasky#include <dev/usb/usb_endian.h>
57248236Shselasky#include <dev/usb/usb_freebsd.h>
58248236Shselasky
59253339Shselasky#include <compat/linux/linux_ioctl.h>
60253339Shselasky
61253339Shselasky#define	IOUSB(a) FBSD_L##a
62253339Shselasky
63248236Shselasky#ifndef __aligned
64248236Shselasky#define	__aligned(x) __attribute__((__aligned__(x)))
65248236Shselasky#endif
66248236Shselasky
67248236Shselasky#ifndef __packed
68248236Shselasky#define	__packed __attribute__((__packed__))
69248236Shselasky#endif
70248236Shselasky
71248236Shselasky#ifndef strlcpy
72248236Shselasky#define	strlcpy(d,s,len) do {			\
73248236Shselasky    strncpy(d,s,len);				\
74248236Shselasky    ((char *)d)[(len) - 1] = 0;			\
75248236Shselasky} while (0)
76248236Shselasky#endif
77248236Shselasky
78358948Shselasky#ifndef TAILQ_FOREACH_SAFE
79358948Shselasky#define	TAILQ_FOREACH_SAFE(var, head, field, tvar)			\
80358948Shselasky	for ((var) = TAILQ_FIRST((head));				\
81358948Shselasky	    (var) && ((tvar) = TAILQ_NEXT((var), field), 1);		\
82358948Shselasky	    (var) = (tvar))
83358948Shselasky#endif
84358948Shselasky
85248236Shselasky#endif					/* _LIBUSB_GLOBAL_LINUX_H_ */
86