Package: libusb-1.0 / 2:1.0.21-1

gnu-hurd-stub.diff Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
Description: Implement stub backend for Hurd
Author: Petter Reinholdtsen <pere@hungry.com>

--- a/libusb/core.c
+++ b/libusb/core.c
@@ -48,6 +48,8 @@
 const struct usbi_os_backend * const usbi_backend = &linux_usbfs_backend;
 #elif defined(OS_DARWIN)
 const struct usbi_os_backend * const usbi_backend = &darwin_backend;
+#elif defined(OS_HURD)
+const struct usbi_os_backend * const usbi_backend = &hurd_backend;
 #elif defined(OS_OPENBSD)
 const struct usbi_os_backend * const usbi_backend = &openbsd_backend;
 #elif defined(OS_NETBSD)
--- a/libusb/libusbi.h
+++ b/libusb/libusbi.h
@@ -533,7 +533,7 @@
 
 /* Internal abstraction for poll (needs struct usbi_transfer on Windows) */
 #if defined(OS_LINUX) || defined(OS_DARWIN) || defined(OS_OPENBSD) || defined(OS_NETBSD) ||\
-	defined(OS_HAIKU) || defined(OS_SUNOS)
+	defined(OS_HAIKU) || defined(OS_SUNOS) || defined(OS_HURD)
 #include <unistd.h>
 #include "os/poll_posix.h"
 #elif defined(OS_WINDOWS) || defined(OS_WINCE)
@@ -1136,6 +1136,7 @@
 
 extern const struct usbi_os_backend linux_usbfs_backend;
 extern const struct usbi_os_backend darwin_backend;
+extern const struct usbi_os_backend hurd_backend;
 extern const struct usbi_os_backend openbsd_backend;
 extern const struct usbi_os_backend netbsd_backend;
 extern const struct usbi_os_backend windows_backend;
--- /dev/null
+++ b/libusb/os/hurd_usb.c
@@ -0,0 +1,214 @@
+/*
+ * Copyright © 2016 Petter Reinholdtsen <pere@hungry.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * Stup libusb implementation for GNU Hurd returning empty list of
+ * devices.  This allow programs to build on Hurd without USB support
+ * without having to update a lot of build dependencies.
+ */
+
+#include "libusbi.h"
+
+static int
+hurd_init(struct libusb_context *ctx)
+{
+	usbi_dbg(__FUNCTION__);
+	return (LIBUSB_ERROR_NOT_SUPPORTED);
+}
+
+static int
+hurd_get_device_list(struct libusb_context * ctx,
+	struct discovered_devs **discdevs)
+{
+	usbi_dbg(__FUNCTION__);
+	return (LIBUSB_ERROR_NOT_SUPPORTED);
+}
+
+static int
+hurd_open(struct libusb_device_handle *handle)
+{
+	usbi_dbg(__FUNCTION__);
+	return (LIBUSB_ERROR_NOT_SUPPORTED);
+}
+
+static void
+hurd_close(struct libusb_device_handle *handle)
+{
+	usbi_dbg(__FUNCTION__);
+}
+
+static int
+hurd_get_device_descriptor(struct libusb_device *dev, unsigned char *buf,
+    int *host_endian)
+{
+	usbi_dbg(__FUNCTION__);
+	return (LIBUSB_ERROR_NOT_SUPPORTED);
+}
+
+int
+hurd_get_active_config_descriptor(struct libusb_device *dev,
+    unsigned char *buf, size_t len, int *host_endian)
+{
+	usbi_dbg(__FUNCTION__);
+	return (LIBUSB_ERROR_NOT_SUPPORTED);
+}
+
+int
+hurd_get_config_descriptor(struct libusb_device *dev, uint8_t idx,
+    unsigned char *buf, size_t len, int *host_endian)
+{
+	usbi_dbg(__FUNCTION__);
+	return (LIBUSB_ERROR_NOT_SUPPORTED);
+}
+
+static int
+hurd_get_configuration(struct libusb_device_handle *handle, int *config)
+{
+	usbi_dbg(__FUNCTION__);
+	return (LIBUSB_ERROR_NOT_SUPPORTED);
+}
+
+static int
+hurd_set_configuration(struct libusb_device_handle *handle, int config)
+{
+	usbi_dbg(__FUNCTION__);
+	return (LIBUSB_ERROR_NOT_SUPPORTED);
+}
+
+static int
+hurd_claim_interface(struct libusb_device_handle *handle, int iface)
+{
+	usbi_dbg(__FUNCTION__);
+	return (LIBUSB_ERROR_NOT_SUPPORTED);
+}
+
+static int
+hurd_release_interface(struct libusb_device_handle *handle, int iface)
+{
+	usbi_dbg(__FUNCTION__);
+	return (LIBUSB_ERROR_NOT_SUPPORTED);
+}
+
+static int
+hurd_set_interface_altsetting(struct libusb_device_handle *handle, int iface,
+    int altsetting)
+{
+	usbi_dbg(__FUNCTION__);
+	return (LIBUSB_ERROR_NOT_SUPPORTED);
+}
+
+static int
+hurd_clear_halt(struct libusb_device_handle *handle, unsigned char endpoint)
+{
+	usbi_dbg(__FUNCTION__);
+	return (LIBUSB_ERROR_NOT_SUPPORTED);
+}
+
+static int
+hurd_reset_device(struct libusb_device_handle *handle)
+{
+	usbi_dbg(__FUNCTION__);
+	return (LIBUSB_ERROR_NOT_SUPPORTED);
+}
+
+static int
+hurd_alloc_streams(struct libusb_device_handle *handle,
+		   uint32_t num_streams, unsigned char *endpoints, int num_endpoints)
+{
+	usbi_dbg(__FUNCTION__);
+	return (LIBUSB_ERROR_NOT_SUPPORTED);
+}
+
+static int
+hurd_free_streams(struct libusb_device_handle *handle,
+		  unsigned char *endpoints, int num_endpoints)
+{
+	usbi_dbg(__FUNCTION__);
+	return (LIBUSB_ERROR_NOT_SUPPORTED);
+}
+
+static void
+hurd_destroy_device(struct libusb_device *dev)
+{
+	usbi_dbg(__FUNCTION__);
+}
+
+static int
+hurd_submit_transfer(struct usbi_transfer *itransfer)
+{
+	usbi_dbg(__FUNCTION__);
+	return (LIBUSB_ERROR_NOT_SUPPORTED);
+}
+
+int
+hurd_cancel_transfer(struct usbi_transfer *itransfer)
+{
+	usbi_dbg(__FUNCTION__);
+	return (LIBUSB_ERROR_NOT_SUPPORTED);
+}
+
+void
+hurd_clear_transfer_priv(struct usbi_transfer *itransfer)
+{
+	usbi_dbg(__FUNCTION__);
+}
+
+int
+hurd_handle_transfer_completion(struct usbi_transfer *itransfer)
+{
+	usbi_dbg(__FUNCTION__);
+	return (LIBUSB_ERROR_NOT_SUPPORTED);
+}
+
+int
+hurd_clock_gettime(int clkid, struct timespec *tp)
+{
+	usbi_dbg("clock %d", clkid);
+
+	if (clkid == USBI_CLOCK_REALTIME)
+		return clock_gettime(CLOCK_REALTIME, tp);
+
+	if (clkid == USBI_CLOCK_MONOTONIC)
+		return clock_gettime(CLOCK_MONOTONIC, tp);
+
+	return (LIBUSB_ERROR_INVALID_PARAM);
+}
+
+const struct usbi_os_backend hurd_backend = {
+	.name = "Synchronous Hurd backend",
+	.caps = 0,
+	.init = hurd_init,
+	.get_device_list = hurd_get_device_list,
+	.open = hurd_open,
+	.close = hurd_close,
+	.get_device_descriptor = hurd_get_device_descriptor,
+	.get_active_config_descriptor = hurd_get_active_config_descriptor,
+	.get_config_descriptor = hurd_get_config_descriptor,
+	.set_configuration = hurd_set_configuration,
+	.claim_interface = hurd_claim_interface,
+	.release_interface = hurd_release_interface,
+	.set_interface_altsetting = hurd_set_interface_altsetting,
+	.clear_halt = hurd_clear_halt,
+	.reset_device = hurd_reset_device,
+	.alloc_streams = hurd_alloc_streams,
+	.free_streams = hurd_free_streams,
+	.submit_transfer = hurd_submit_transfer,
+	.cancel_transfer = hurd_cancel_transfer,
+	.clear_transfer_priv = hurd_clear_transfer_priv,
+	.clock_gettime = hurd_clock_gettime,
+};
--- a/configure.ac
+++ b/configure.ac
@@ -67,6 +67,11 @@
 	backend="darwin"
 	threads="posix"
 	;;
+*-gnu*)
+	AC_MSG_RESULT([Hurd])
+	backend="hurd"
+	threads="posix"
+	;;
 *-openbsd*)
 	AC_MSG_RESULT([OpenBSD])
 	backend="openbsd"
@@ -151,6 +156,14 @@
 		[AC_DEFINE([POLL_NFDS_TYPE],[unsigned int],[type of second poll() argument])],
 		[#include <poll.h>])
 	;;
+hurd)
+	AC_DEFINE(OS_HURD, 1, [Hurd backend])
+	AC_SUBST(OS_HURD)
+	THREAD_CFLAGS="-pthread"
+	LIBS="-pthread"
+	AC_CHECK_HEADERS([poll.h])
+	AC_DEFINE([POLL_NFDS_TYPE],[nfds_t],[type of second poll() argument])
+	;;
 openbsd)
 	AC_DEFINE(OS_OPENBSD, 1, [OpenBSD backend])
 	AC_SUBST(OS_OPENBSD)
@@ -204,6 +217,7 @@
 
 AM_CONDITIONAL(OS_LINUX, test "x$backend" = xlinux)
 AM_CONDITIONAL(OS_DARWIN, test "x$backend" = xdarwin)
+AM_CONDITIONAL(OS_HURD, test "x$backend" = xhurd)
 AM_CONDITIONAL(OS_OPENBSD, test "x$backend" = xopenbsd)
 AM_CONDITIONAL(OS_SUNOS, test "x$backend" = xsunos)
 AM_CONDITIONAL(OS_NETBSD, test "x$backend" = xnetbsd)
--- a/libusb/Makefile.am
+++ b/libusb/Makefile.am
@@ -20,6 +20,7 @@
 WINCE_USB_SRC = os/wince_usb.h os/wince_usb.c
 HAIKU_USB_SRC = os/haiku_usb.h os/haiku_usb_backend.cpp \
 		os/haiku_usb_raw.h os/haiku_usb_raw.cpp os/haiku_pollfs.cpp
+HURD_USB_SRC = os/hurd_usb.c
 
 EXTRA_DIST = $(POSIX_POLL_SRC) $(POSIX_THREADS_SRC) \
 	$(WINDOWS_POLL_SRC) $(WINDOWS_THREADS_SRC) \
@@ -62,6 +63,10 @@
 libusb_1_0_la_LIBADD = libusb_haiku.la
 endif
 
+if OS_HURD
+OS_SRC = $(HURD_USB_SRC)
+endif
+
 if OS_WINDOWS
 
 if USE_USBDK