diff --git a/usb/device.go b/usb/device.go index c51a648..d016b25 100644 --- a/usb/device.go +++ b/usb/device.go @@ -205,16 +205,23 @@ found: } func (d *Device) GetStringDescriptor(desc_index int) (string, error) { + + // allocate 200-byte array limited the length of string descriptor goBuffer := make([]byte, 200) + + // get string descriptor from libusb. if errno < 0 then there are any errors. + // if errno >= 0; it is a length of result string descriptor errno := C.libusb_get_string_descriptor_ascii( d.handle, C.uint8_t(desc_index), (*C.uchar)(unsafe.Pointer(&goBuffer[0])), 200) + // if any errors occur if errno < 0 { return "", fmt.Errorf("usb: getstr: %s", usbError(errno)) } + // convert slice of byte to string with limited length from errno stringDescriptor := string(goBuffer[:errno]) return stringDescriptor, nil diff --git a/usb/usb.go b/usb/usb.go index d188d4d..6029dbd 100644 --- a/usb/usb.go +++ b/usb/usb.go @@ -16,8 +16,8 @@ package usb // #cgo windows CFLAGS: -ID:/lib/libusb-1.0.19/include -// #cgo windows amd64 LDFLAGS: D:/lib/libusb-1.0.19/MinGW64/static/libusb-1.0.a -// #cgo windows 386 LDFLAGS: D:/lib/libusb-1.0.19/MinGW32/static/libusb-1.0.a +// #cgo windows,amd64 LDFLAGS: D:/lib/libusb-1.0.19/MinGW64/static/libusb-1.0.a +// #cgo windows,386 LDFLAGS: D:/lib/libusb-1.0.19/MinGW32/static/libusb-1.0.a // #cgo !windows LDFLAGS: -lusb-1.0 // #include import "C" diff --git a/usb/usb.test b/usb/usb.test deleted file mode 100755 index 2cd1d0f..0000000 Binary files a/usb/usb.test and /dev/null differ