Fix output report length bug

On Windows, data shorter than the output report length must be padded.
This is because in the case of multiple reports, Windows expects the number
of bytes which are in the _longest_ report to be given to WriteFile() even
if the user is sending a report which has fewer bytes.

This allocates a temporary buffer in the case that the user passes in too
few bytes.

From: Vitali Lovich <vlovich@gmail.com>
Modified-by: Alan Ott <alan@signal11.us>
Don't copy too many bytes from hid_read() in Windows.

Make sure that too many bytes aren't copied to the user if they pass in a
short buffer to hid_read_*().

From: Vitali Lovich <vlovich@gmail.com>
Fix string copy logic in Mac backend

This makes sure that a valid range is given to the string copy & that
the returned string always has a valid null-terminator.
Fix hidapi enumeration bug on OSX

Surrounding application may not be using a run loop (or may not have
given it a chance to run).  Process any outstanding events (this does
imply that hid_enumerate will take about at least 1ms to process).
Remove the extraneous call to IOHIDDeviceClose() in the read_thread()

The call is also made in hid_close(). Thanks to Vitali Lovich for pointing this out.
Fix hid_enumerate() crash on Mac OS X

Fix the problem where hid_enumerate() will crash if any of the HID devices
attached to the system are opened in exclusive mode (using
kIOHIDOptionsTypeSeizeDevice from IOHIDManagerOpen()). According to reports,
some Logitech devices have software which opens devices in exclusive mode,
causing HIDAPI-based programs to crash on systems where these Logitech
devices (and their accompanying software) are installed.

The fix is simple enough. IOHIDManagerOpen() does not need to be called from
HIDAPI, contrary to the examples in Apple's Technical Note TN2187.  From
examining the IOHIDManager source[1], it appears that "opening" the
IOHIDManager (not the IOHIDDevice) causes IOHIDManager to try to open all
matching devices connected to the system, failing if even one device cannot
be opened.  (Calling IOHIDManagerOpen() does indeed call IOHIDDeviceOpen()
for every matching connected device and for every future matching connected
device as well).  HIDAPI of course tries to match all devices (by passing
NULL to IOHIDManagerSetDeviceMatching()), hence the issue.

Empirical evidence first suggested that IOHIDManagerOpen() did not actually
need to be called, and examination of the source[1] seems to confirm that it
only gets in the way.

Many thanks to Brendan Shanks, Bill Good, Github user darthrake, and Vitali
Lovich for pointing this out and participating in the information gathering,
debugging, and discussion.

[1] http://opensource.apple.com/source/IOKitUser/IOKitUser-502/hid.subproj/IOHIDManager.c

Signed-off-by: Alan Ott <alan@signal11.us>
README.txt: Clarification of what the sample program does.
Use private libusb_context for linux/libusb implementation.

Use a private libusb_context to avoid conflicts between
multiple libusb instances inside a single application
process. Many 3rd party libraries use libusb as backend,
so there is a good chance of collisions if the default NULL
context is used.

Modified by Alan Ott to also remove the initialized
variable since it's no longer needed (since we can use
the context instead), to make the style consistent, and
to remove unnecessary checks for initialized before calling
hid_init().

Signed-off-by: Mario Kleiner <mario.kleiner@tuebingen.mpg.de>
Signed-off-by: Alan Ott <alan@signal11.us>
Windows: Don't let device disappear from hid_enumerate() when open

Change the CreateFileA() flags to support the following:
1. Devices can still be opened in exclusive mode,
2. Devices which must be opened in shared mode can still be opened.
3. Opened devices (even with exclusive opens) still show in
hid_enumerate()

Thanks to github user vanweric for suggesting these flags and to Brendan
Shanks for discussion and testing.
Merge branch 'master' of github.com:signal11/hidapi
Remove unnecessary setlocale() on Mac
Linux: Don't set locale if it's already been set

Adapted from a patch received from Axel Rohde <axel.rohde@gmail.com>
Linux: Took out one more setlocale()
Linux/hidraw: Fix return value string functions
	get_serial_number()
	get_manufacturer_string()
	get_product_string()

This matches the documentation in header file to return 0 on success and -1
on error.
Mac: Fix return value for string functions
	get_serial_number()
	get_manufacturer_string()
	get_product_string()

This is to match the documentation in the header file, returning 0 on
success and -1 on error.
Linux: Added make targets for building shared libraries.
Linux: Clean up Makefile

Create separate targets for libusb and hidraw implementations.
Build shared libraries in a more standard way.
Add Comments.
All: Make serial_number parameter to hid_open() const.

This prevents a warning when passing in a literal.
Fixed a typo that made the shared libraries be empty. Added the hidtest-* binaries to the list of files ignored by git.
Linux/libusb: Shutdown thread if it's not possible to submit transfer

This happens if a device gets opened a second time. The call to
libusb_submit_transfer() will fail, indicating that the read thread should
be shut down.