-g/c usbd_init()/usbd_finish() which don't do anything useful
-use <fs/unicode.h> for utf16->utf8 conversion instead of a private implementation -streamline the COMPAT_30 utf16->ascii conversion a bit: remove length check (USB_MAX_STRING_LEN is too large to be useful) and replace array index arithmetics
This commit is contained in:
parent
515beb215f
commit
47032dbc5e
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: usbdi.c,v 1.118 2007/02/10 07:52:29 mlelstv Exp $ */
|
||||
/* $NetBSD: usbdi.c,v 1.119 2007/02/26 13:44:40 drochner Exp $ */
|
||||
/* $FreeBSD: src/sys/dev/usb/usbdi.c,v 1.28 1999/11/17 22:33:49 n_hibma Exp $ */
|
||||
|
||||
/*
|
||||
@ -39,7 +39,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.118 2007/02/10 07:52:29 mlelstv Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.119 2007/02/26 13:44:40 drochner Exp $");
|
||||
|
||||
#include "opt_compat_netbsd.h"
|
||||
|
||||
@ -69,6 +69,9 @@ __KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.118 2007/02/10 07:52:29 mlelstv Exp $");
|
||||
#include <dev/usb/usb_mem.h>
|
||||
#include <dev/usb/usb_quirks.h>
|
||||
|
||||
/* UTF-8 encoding stuff */
|
||||
#include <fs/unicode.h>
|
||||
|
||||
#ifdef USB_DEBUG
|
||||
#define DPRINTF(x) if (usbdebug) logprintf x
|
||||
#define DPRINTFN(n,x) if (usbdebug>(n)) logprintf x
|
||||
@ -85,20 +88,6 @@ Static void usbd_start_next(usbd_pipe_handle pipe);
|
||||
Static usbd_status usbd_open_pipe_ival
|
||||
(usbd_interface_handle, u_int8_t, u_int8_t, usbd_pipe_handle *, int);
|
||||
|
||||
Static int usbd_nbuses = 0;
|
||||
|
||||
void
|
||||
usbd_init(void)
|
||||
{
|
||||
usbd_nbuses++;
|
||||
}
|
||||
|
||||
void
|
||||
usbd_finish(void)
|
||||
{
|
||||
--usbd_nbuses;
|
||||
}
|
||||
|
||||
static inline int
|
||||
usbd_xfer_isread(usbd_xfer_handle xfer)
|
||||
{
|
||||
@ -1218,30 +1207,19 @@ usbd_get_string0(usbd_device_handle dev, int si, char *buf, int unicode)
|
||||
c = UGETW(us.bString[i]);
|
||||
if (swap)
|
||||
c = (c >> 8) | (c << 8);
|
||||
if (c < 0x0080) {
|
||||
*s++ = c;
|
||||
} else if (c < 0x0800) {
|
||||
*s++ = 0xc0 | (c >> 6);
|
||||
*s++ = 0x80 | (c & 0x3f);
|
||||
} else {
|
||||
*s++ = 0xe0 | (c >> 12);
|
||||
*s++ = 0x80 | ((c >> 6) & 0x3f);
|
||||
*s++ = 0x80 | (c & 0x3f);
|
||||
}
|
||||
s += wput_utf8(s, 3, c);
|
||||
}
|
||||
*s++ = 0;
|
||||
}
|
||||
#ifdef COMPAT_30
|
||||
else {
|
||||
int j;
|
||||
for (i = j = 0; i < n && j < USB_MAX_STRING_LEN - 1; i++) {
|
||||
for (i = 0; i < n; i++) {
|
||||
c = UGETW(us.bString[i]);
|
||||
if (swap)
|
||||
c = (c >> 8) | (c << 8);
|
||||
/* Encode (16-bit) Unicode as UTF8. */
|
||||
s[j++] = (c < 0x80) ? c : '?';
|
||||
*s++ = (c < 0x80) ? c : '?';
|
||||
}
|
||||
s[j] = 0;
|
||||
*s++ = 0;
|
||||
}
|
||||
#endif
|
||||
return (USBD_NORMAL_COMPLETION);
|
||||
|
Loading…
Reference in New Issue
Block a user