1 /*
2  * Copyright (C) 2009      Citrix Ltd.
3  * Author Stefano Stabellini <stefano.stabellini@eu.citrix.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published
7  * by the Free Software Foundation; version 2.1 only. with the special
8  * exception on linking described in file LICENSE.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  */
15 
16 /*
17  * This header must be included first, before any system headers,
18  * so that _GNU_SOURCE takes effect properly.
19  */
20 
21 #ifndef LIBXL_OSDEP
22 #define LIBXL_OSDEP
23 
24 #define _GNU_SOURCE
25 
26 #if defined(__NetBSD__)
27 #define SYSFS_USB_DEV          "/sys/bus/usb/devices"
28 #define SYSFS_USBBACK_DRIVER   "/kern/xen/usb"
29 #define SYSFS_PCI_DEV          "/sys/bus/pci/devices"
30 #define SYSFS_PCIBACK_DRIVER   "/kern/xen/pci"
31 #define NETBACK_NIC_NAME       "xvif%ui%d"
32 #include <util.h>
33 #include <uuid.h>
34 #elif defined(__OpenBSD__)
35 #include <util.h>
36 #elif defined(__linux__)
37 #define SYSFS_USB_DEV          "/sys/bus/usb/devices"
38 #define SYSFS_USBBACK_DRIVER   "/sys/bus/usb/drivers/usbback"
39 #define SYSFS_PCI_DEV          "/sys/bus/pci/devices"
40 #define SYSFS_PCIBACK_DRIVER   "/sys/bus/pci/drivers/pciback"
41 #define NETBACK_NIC_NAME       "vif%u.%d"
42 #include <sys/sysmacros.h>
43 #include <pty.h>
44 #include <uuid/uuid.h>
45 #elif defined(__sun__)
46 #include <stropts.h>
47 #elif defined(__FreeBSD__)
48 #define SYSFS_USB_DEV          "/dev/null"
49 #define SYSFS_USBBACK_DRIVER   "/dev/null"
50 #define SYSFS_PCI_DEV          "/dev/null"
51 #define SYSFS_PCIBACK_DRIVER   "/dev/null"
52 #define NETBACK_NIC_NAME       "xnb%u.%d"
53 #include <libutil.h>
54 #include <sys/endian.h>
55 #include <uuid.h>
56 /*
57  * FreeBSD doesn't have ENODATA errno ATM, so privcmd always translates
58  * ENODATA into ENOENT.
59  */
60 #ifndef ENODATA
61 #define ENODATA ENOENT
62 #endif
63 #endif
64 
65 #ifndef SYSFS_USBBACK_DRIVER
66 #error define SYSFS_USBBACK_DRIVER for your platform
67 #endif
68 #ifndef SYSFS_USB_DEV
69 #error define SYSFS_USB_DEV for your platform
70 #endif
71 
72 #ifndef SYSFS_PCIBACK_DRIVER
73 #error define SYSFS_PCIBACK_DRIVER for your platform
74 #endif
75 #ifndef SYSFS_PCI_DEV
76 #error define SYSFS_PCI_DEV for your platform
77 #endif
78 
79 #ifdef NEED_OWN_ASPRINTF
80 #include <stdarg.h>
81 
82 int asprintf(char **buffer, char *fmt, ...);
83 int vasprintf(char **buffer, const char *fmt, va_list ap);
84 #endif /*NEED_OWN_ASPRINTF*/
85 
86 #ifndef htobe32 /* glibc < 2.9 */
87 # include <byteswap.h>
88 
89 # if __BYTE_ORDER == __LITTLE_ENDIAN
90 #  define htobe16(x) __bswap_16(x)
91 #  define htole16(x) (x)
92 #  define be16toh(x) __bswap_16(x)
93 #  define le16toh(x) (x)
94 
95 #  define htobe32(x) __bswap_32(x)
96 #  define htole32(x) (x)
97 #  define be32toh(x) __bswap_32(x)
98 #  define le32toh(x) (x)
99 
100 #  define htobe64(x) __bswap_64(x)
101 #  define htole64(x) (x)
102 #  define be64toh(x) __bswap_64(x)
103 #  define le64toh(x) (x)
104 # else
105 #  define htobe16(x) (x)
106 #  define htole16(x) __bswap_16(x)
107 #  define be16toh(x) (x)
108 #  define le16toh(x) __bswap_16(x)
109 
110 #  define htobe32(x) (x)
111 #  define htole32(x) __bswap_32(x)
112 #  define be32toh(x) (x)
113 #  define le32toh(x) __bswap_32(x)
114 
115 #  define htobe64(x) (x)
116 #  define htole64(x) __bswap_64(x)
117 #  define be64toh(x) (x)
118 #  define le64toh(x) __bswap_64(x)
119 # endif
120 #endif
121 
122 #endif
123 
124 /*
125  * Local variables:
126  * mode: C
127  * c-basic-offset: 4
128  * indent-tabs-mode: nil
129  * End:
130  */
131