Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/dev/usb/usbdi.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/dev/usb/usbdi.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.114 retrieving revision 1.115 diff -u -p -r1.114 -r1.115 --- src/sys/dev/usb/usbdi.c 2006/11/16 01:33:27 1.114 +++ src/sys/dev/usb/usbdi.c 2006/12/03 22:34:58 1.115 @@ -1,4 +1,4 @@ -/* $NetBSD: usbdi.c,v 1.114 2006/11/16 01:33:27 christos Exp $ */ +/* $NetBSD: usbdi.c,v 1.115 2006/12/03 22:34:58 pavel Exp $ */ /* $FreeBSD: src/sys/dev/usb/usbdi.c,v 1.28 1999/11/17 22:33:49 n_hibma Exp $ */ /* @@ -39,7 +39,9 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.114 2006/11/16 01:33:27 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: usbdi.c,v 1.115 2006/12/03 22:34:58 pavel Exp $"); + +#include "opt_compat_netbsd.h" #include #include @@ -1180,10 +1182,16 @@ usb_desc_iter_next(usbd_desc_iter_t *ite usbd_status usbd_get_string(usbd_device_handle dev, int si, char *buf) { + return usbd_get_string0(dev, si, buf, 1); +} + +usbd_status +usbd_get_string0(usbd_device_handle dev, int si, char *buf, int unicode) +{ int swap = dev->quirks->uq_flags & UQ_SWAP_UNICODE; usb_string_descriptor_t us; char *s; - int i, n; + int i, j, n; u_int16_t c; usbd_status err; int size; @@ -1210,23 +1218,36 @@ usbd_get_string(usbd_device_handle dev, return (err); s = buf; n = size / 2 - 1; - for (i = 0; i < n; i++) { - c = UGETW(us.bString[i]); - if (swap) - c = (c >> 8) | (c << 8); - /* Encode (16-bit) Unicode as UTF8. */ - 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); + if (unicode) { + for (i = 0; i < n; i++) { + 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++ = 0; } - *s++ = 0; +#ifdef COMPAT_30 + else { + for (i = j = 0; i < n && j < USB_MAX_STRING_LEN - 1; 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[j] = 0; + } +#endif return (USBD_NORMAL_COMPLETION); }