File: bsd-libusb

package info (click to toggle)
qthid-fcd-controller 4.1-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,616 kB
  • sloc: ansic: 5,459; cpp: 2,269; xml: 18; makefile: 18; sh: 14
file content (114 lines) | stat: -rw-r--r-- 2,856 bytes parent folder | 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
Description: bsd libusb
 Support the libusb found on bsd systems.
Author: A. Maitland Bottoms <bottoms@debian.org>

--- a/hid-libusb.c
+++ b/hid-libusb.c
@@ -270,7 +270,7 @@
 
 #endif
 
-
+#ifndef __FreeBSD_kernel__
 /* Get the first language the device says it reports. This comes from
    USB string #0. */
 static uint16_t get_first_language(libusb_device_handle *dev)
@@ -315,7 +315,7 @@
 
 	return 0;
 }
-
+#endif
 
 /* This function returns a newly allocated wide string containing the USB
    device string numbered by the index. The returned string must be freed
@@ -339,6 +339,25 @@
 #endif
 	char *outptr;
 
+#ifdef __FreeBSD_kernel__
+        /* Get the string from libusb. */
+        len = libusb_get_string_descriptor_ascii(dev,
+                        idx,
+                        (unsigned char*)buf,
+                        sizeof(buf));
+        if (len < 0)
+                return NULL;
+
+        buf[sizeof(buf)-1] = '\0';
+
+        if (len+1 < sizeof(buf))
+                buf[len+1] = '\0';
+
+        /* Initialize iconv. */
+        ic = iconv_open("UTF-32", "ASCII");
+        if (ic == (iconv_t)-1)
+                return NULL;
+#else
 	/* Determine which language to use. */
 	uint16_t lang;
 	lang = get_usb_code_for_current_locale();
@@ -363,7 +382,7 @@
 		LOG("iconv_open() failed\n");
 		return NULL;
 	}
-	
+#endif	
 	/* Convert to native wchar_t (UTF-32 on glibc/BSD systems).
 	   Skip the first character (2-bytes). */
 	inptr = buf+2;
--- a/v2/hid-libusb.c
+++ b/v2/hid-libusb.c
@@ -252,7 +252,7 @@
 }
 #endif // INVASIVE_GET_USAGE
 
-
+#ifndef __FreeBSD_kernel__
 /* Get the first language the device says it reports. This comes from
    USB string #0. */
 static uint16_t get_first_language(libusb_device_handle *dev)
@@ -297,7 +297,7 @@
 
 	return 0;
 }
-
+#endif
 
 /* This function returns a newly allocated wide string containing the USB
    device string numbered by the index. The returned string must be freed
@@ -317,6 +317,25 @@
 	char *inptr;
 	char *outptr;
 
+#ifdef __FreeBSD_kernel__
+        /* Get the string from libusb. */
+        len = libusb_get_string_descriptor_ascii(dev,
+                        idx,
+                        (unsigned char*)buf,
+                        sizeof(buf));
+        if (len < 0)
+                return NULL;
+
+        buf[sizeof(buf)-1] = '\0';
+
+        if (len+1 < sizeof(buf))
+                buf[len+1] = '\0';
+
+        /* Initialize iconv. */
+        ic = iconv_open("UTF-32", "ASCII");
+        if (ic == (iconv_t)-1)
+                return NULL;
+#else
 	/* Determine which language to use. */
 	uint16_t lang;
 	lang = get_usb_code_for_current_locale();
@@ -342,6 +361,8 @@
 	if (ic == (iconv_t)-1)
 		return NULL;
 	
+#endif
+
 	/* Convert to UTF-32 (wchar_t on glibc systems).
 	   Skip the first character (2-bytes). */
 	inptr = buf+2;