1
0
mirror of git://sigrok.org/libserialport synced 2023-08-10 21:13:24 +03:00
Commit Graph

25 Commits

Author SHA1 Message Date
Martin Ling
d6412d2801 windows: Fix another CreateFile usage.
When built with MSVC with unicode enabled, this gave:

warning C4133: 'function': incompatible types - from 'char *' to 'LPCWSTR'

due to CreateFile expanding to CreateFileW which accepts UTF-16 filenames.

The device name used here is in 8-bit format, having come from a call to
wc_to_utf8() in either get_root_hub_name() or get_external_hub_name(). So
we need to use CreateFileA.
2020-01-26 21:11:46 +01:00
Martin Ling
60fc49ceab windows: Fix a warning on size_t to USHORT conversion.
Building with MSVC gave:
warning C4267: '=': conversion from 'size_t' to 'USHORT', possible loss of data

The value here is known to be safe for the sizes involved. Add an
explicit cast to suppress the warning.
2020-01-26 21:11:46 +01:00
Martin Ling
e47c7dcbff windows: Use correct variant of CreateFile.
When built with MSVC and unicode enabled, using CreateFile gave:

warning C4133: 'function': incompatible types - from 'char *' to 'LPCWSTR'

CreateFile is a macro expanding to either CreateFileW if unicode
mode is enabled, or CreateFileA if not.

For CreateFileW, the filename is a UTF-16 string. For CreateFileA
it is an 'ANSI' string, meaning 8-bit chars in the current Windows
code page.

We do need to stick to 8-bit strings for port names, since
sp_get_port_by_name() and sp_get_port_name() are defined with
char * types, and that is what we store in struct sp_port. So
CreateFileA is the correct version to use.

Since Windows serial port names are always just 'COM' and a digit,
with a '\\.\' prefix for higher numbers, encoding is fortunately
not an issue - ASCII, UTF-8 and all the Windows code pages seem to
be equivalent for these characters.

We should however explicitly document what the encoding of strings
accepted and returned by libserialport is.
2020-01-24 05:39:16 +00:00
Martin Ling
e919e2efaa Adjust headers and include ordering for MSVC support. 2020-01-24 05:39:12 +00:00
Martin Ling
6aaf844863 windows: wc_to_utf8: use some clearer variable names. 2020-01-23 03:35:47 +00:00
Martin Ling
a9900f8b64 windows: wc_to_utf8: Eliminate variable-length array.
This should enable compatibility with MSVC.
2020-01-23 03:35:47 +00:00
Martin Ling
8488868187 windows: Handle the case where there are no serial ports at all.
It's possible for the HARDWARE\DEVICEMAP\SERIALCOMM key to not exist in
the registry if there are no serial ports at all and never have been, as
discovered on my rather minimalist gaming machine.

Handle that case gracefully and return an empty list.
2020-01-23 03:35:47 +00:00
Martin Ling
c79e0ac8ef windows: Handle registry lookup failures correctly.
RegOpenKeyEx() and RegQueryInfoKey() return system error codes directly,
not by setting the thread-local errno equivalent that is returned by
GetLastError().

When returning SP_ERR_FAIL, our API specifies that sp_last_error_code()
may be called immediately afterwards to get the system error code. In
this case that would not work, as it would call GetLastError() and miss
the directly-returned result.

We therefore need to call SetLastError() with the error code before
returning with SP_ERR_FAIL.
2020-01-23 03:35:47 +00:00
Uwe Hermann
81243567bc Random minor whitespace fixes. 2019-12-28 19:23:30 +01:00
Uwe Hermann
2e0437c28e windows: Fix incorrect wc_to_utf8() calls.
This fixes bug #1079.
2019-12-28 17:08:49 +01:00
Martin Jackson
38b71192dd windows: wc_to_utf8(): Fix a WCHAR related issue causing crashes.
In wc_to_utf8() in windows.c, the zero terminator is written to an invalid
array index, which results in 2 bytes being zeroed in a random place in the
stack. This sometimes causes a crash when running sp_list_ports() (depending
on string length and compiler optimisation settings).

sizeof(wc_str) returns the size in bytes, so cannot be used directly as an
index into that array, it should be divided by sizeof(WCHAR). Otherwise the
zero terminator index is approximately twice what it should be.

This fixes bug #1031.
2019-06-30 14:23:59 +02:00
Martino Facchin
02c8a1424d windows: Fix iSerial for composite devices.
USB composite devices can contain an ACM serial interface.
On Windows, the correct iSerial descriptor field is assigned to the parent
(composite) device instead of to the actual serial interface. A bogus
value is returned if the serial interface is asked to provide the S/N.
This patch provides a fallback for this kind of device (tested on Android
with adb + cdc gadgets and on Arduino Zero Programming Port)
2016-01-06 13:54:17 +00:00
Daniel Elstner
1a584c45b0 Build: Include config.h first in all source files 2015-09-13 20:04:31 +02:00
Uwe Hermann
eb50b1aca6 windows.c: Constify a few function parameters. 2015-04-19 19:50:56 +02:00
Uwe Hermann
dc422c04af Various cosmetic and consistency fixes. 2015-03-26 23:57:56 +01:00
Aurelien Jacobs
b328a48b0f windows: Properly handle return value of SetupDiOpenDevRegKey().
This fixes bug #499.
2014-11-27 17:42:28 +01:00
Bert Vermeulen
d66bbceaa7 Fix typos. 2014-10-05 02:38:35 +02:00
Aurelien Jacobs
6c444ade55 windows: Indentation (cosmetics only). 2014-09-24 12:54:36 +02:00
Aurelien Jacobs
7aeb6736bd windows: Fix various memory leaks.
This fixes bug #419.
2014-09-24 12:52:21 +02:00
Uwe Hermann
d38c7d2c70 Fix Windows build. 2014-08-27 14:53:19 +02:00
Uwe Hermann
34906a229b windows.c: Remove MinGW workarounds, require MinGW-w64 instead.
We're switching from MinGW (i686-pc-mingw32.static in MXE)...

  http://mingw.org/

...to MinGW-w64 (i686-w64-mingw32.static in MXE):

  http://mingw-w64.sourceforge.net/

The latter is a fork which nowadays seems to be more active and also to
have a more complete set of win32 API headers and libs.

History:
http://sourceforge.net/p/mingw-w64/wiki2/History/

This closes bug #393.
2014-08-05 21:22:50 +02:00
Uwe Hermann
8eb18f7b5a windows.c: Define a bunch of stuff that's not in MinGW, yet.
Without these defineѕ the build fails with various (many) compile errors.
2014-07-31 23:14:35 +02:00
Aurelien Jacobs
970f279ae4 Introduce SP_API/SP_PRIV to mark visibility of functions. 2014-07-02 14:43:32 +02:00
Aurelien Jacobs
48a4076f69 Move list_ports() implementations to OS-specific files. 2014-06-14 01:28:49 +02:00
Martin Ling
e33dcf90a0 Tidy up and split most OS-specific code to separate files. 2014-06-11 15:10:29 +01:00