]> sigrok.org Git - libserialport.git/log
libserialport.git
5 months agochange type of result variables to ssize_t master github/master
André Fonseca [Tue, 29 Aug 2023 08:11:10 +0000 (10:11 +0200)]
change type of result variables to ssize_t

These variables are being used to store the result of read/write calls,
which return a ssize_t value, which depending on platform can be bigger
than an int.

5 months agorename deprecated constant kIOMasterPortDefault
André Fonseca [Mon, 28 Aug 2023 13:28:22 +0000 (15:28 +0200)]
rename deprecated constant kIOMasterPortDefault

This constant is now deprecated since macOS 12.0 and a new constant
named kIOMainPortDefault is provided. There is a fallback in place
that retains compatibility for older macOS versions.

https://developer.apple.com/documentation/iokit/kiomasterportdefault

[ gsi: tweak style to match existing code base ]

2 years agoHACK: don't even check for termiox
Karl Palsson [Fri, 11 Jun 2021 17:07:09 +0000 (17:07 +0000)]
HACK: don't even check for termiox

termiox was removed from linux in e0efb3168d34
Some more information available in https://www.spinics.net/lists/linux-serial/msg41926.html

Attempting to use the termiox ioctls on more modern kernels results in
"Inappropriate IOCTL" errors.

While the "right" solution might be to remove the termiox code from the
linux path, simply not checking for termiox builds a libserialport that
functions on modern linux kernels.

Signed-off-by: Karl Palsson <redacted>
2 years agoApply a default baudrate when the OS does not provide one.
Jerry Jacobs [Mon, 14 Jun 2021 16:22:58 +0000 (18:22 +0200)]
Apply a default baudrate when the OS does not provide one.

Handle the situation when the OS does not provide a baudrate in the code
path which opens the serial port. See bug #1632 and PR #6 for details.

  https://sigrok.org/bugzilla/show_bug.cgi?id=1632
  https://github.com/sigrokproject/libserialport/pull/6

This resolves bug #1632.

[ gsi: adjust comment style, rephrase comment and commit message ]

2 years agodoc: update IRC reference to Libera.Chat
Gerhard Sittig [Wed, 16 Jun 2021 18:51:42 +0000 (20:51 +0200)]
doc: update IRC reference to Libera.Chat

3 years agosp: clear HUPCL to preserve control lines on close
Ben Gardiner [Tue, 22 Sep 2020 03:10:08 +0000 (03:10 +0000)]
sp: clear HUPCL to preserve control lines on close

The comment and code are out of sync. The comments say "leave control
lines alone on close." The HUPCL bit, when set, will "Lower modem control
lines after last process closes the device (hang up)."

To match the intent captured in the comment, the HUPCL bit should be
cleared.

Signed-off-by: Ben Gardiner <redacted>
3 years agoReturn proper type when sp_get_port_transport() fails
Wolfram Sang [Sun, 5 Apr 2020 21:24:50 +0000 (23:24 +0200)]
Return proper type when sp_get_port_transport() fails

The above function must always return an 'enum sp_transport'. So, return
NATIVE if no port is present because its effective meaning within the
API is "you shouldn't call any transport-specific functions for this
port handle".

Fixes bug #1531.

Signed-off-by: Wolfram Sang <redacted>
4 years agoOpen the file descriptor of a serial port on POSIX systems exclusively
Leon Varga [Tue, 3 Mar 2020 13:18:53 +0000 (14:18 +0100)]
Open the file descriptor of a serial port on POSIX systems exclusively

This fixes bug #1510.

4 years agoexamples/send_receive: Fix receive check.
Uwe Hermann [Thu, 26 Mar 2020 21:38:41 +0000 (22:38 +0100)]
examples/send_receive: Fix receive check.

4 years agoFix use of variable length array in send_receive example, for MSVC.
Martin Ling [Fri, 7 Feb 2020 14:09:06 +0000 (14:09 +0000)]
Fix use of variable length array in send_receive example, for MSVC.

4 years agoAdd send/receive example to VS2019 examples solution.
Martin Ling [Fri, 7 Feb 2020 13:56:45 +0000 (13:56 +0000)]
Add send/receive example to VS2019 examples solution.

4 years agowindows: Ignore fParity flag which is always 0 after GetCommState().
Martin Ling [Fri, 7 Feb 2020 11:16:32 +0000 (11:16 +0000)]
windows: Ignore fParity flag which is always 0 after GetCommState().

This is a known bug in Windows: https://stackoverflow.com/a/36650872

Reported here: https://github.com/martinling/libserialport/issues/36

4 years agoREADME: Remove note about old MinGW, it actually works fine.
Martin Ling [Fri, 7 Feb 2020 10:48:48 +0000 (10:48 +0000)]
README: Remove note about old MinGW, it actually works fine.

4 years agoconfigure.ac: remove broken handling for cygwin as $host_os.
Martin Ling [Fri, 7 Feb 2020 10:39:00 +0000 (10:39 +0000)]
configure.ac: remove broken handling for cygwin as $host_os.

I don't think these two mentions of cygwin ever did anything useful.
In fact they stop libserialport being buildable under cygwin.

The first one caused builds on cygwin to try to build windows.c,
which uses the Win32 API, not the POSIX layer provided by cygwin.

The second asserts that enumeration and port metadata are supported
on cygwin, but that isn't the case.

Without these matches for cygwin as $host_os, libserialport builds
and works just fine on old-school cygwin with the original mingw32.

The only reason that MSYS2 worked better is that it uses "msys" as
the $host_os identifier, not cygwin.

4 years agoAdd remaining examples to examples/README.
Martin Ling [Sun, 2 Feb 2020 10:57:27 +0000 (10:57 +0000)]
Add remaining examples to examples/README.

4 years agoFormatting fix for example descriptions.
Martin Ling [Sun, 2 Feb 2020 10:51:47 +0000 (10:51 +0000)]
Formatting fix for example descriptions.

4 years agoAdd example of sending and receiving data.
Martin Ling [Sun, 2 Feb 2020 10:51:07 +0000 (10:51 +0000)]
Add example of sending and receiving data.

4 years agounix: Fix calculation of poll() timeout in sp_wait().
Martin Ling [Sun, 2 Feb 2020 09:36:52 +0000 (09:36 +0000)]
unix: Fix calculation of poll() timeout in sp_wait().

4 years agoMinor whitespace- and consistency fixes.
Uwe Hermann [Sun, 26 Jan 2020 20:18:49 +0000 (21:18 +0100)]
Minor whitespace- and consistency fixes.

4 years agoREADME: Add note on building for MSYS2/Cygwin.
Martin Ling [Sat, 25 Jan 2020 16:06:49 +0000 (16:06 +0000)]
README: Add note on building for MSYS2/Cygwin.

4 years agoRelax timing test in the other direction.
Martin Ling [Sat, 25 Jan 2020 14:54:39 +0000 (14:54 +0000)]
Relax timing test in the other direction.

On my test system under MSYS (Cygwin64), a period of 991ms was
measured after a sleep of 1s.

4 years agoFix building on Cygwin.
Martin Ling [Sat, 25 Jan 2020 14:51:56 +0000 (14:51 +0000)]
Fix building on Cygwin.

There were two issues: first, feature test macros were only defined
for __linux__, so defintions we needed were not included. Enable the
same feature test macros for __CYGWIN__.

Second, the Cygwin headers do not define TIOCOUTQ, needed to use
ioctl() to get the number of bytes in the output queue. Return
SP_ERR_SUPP on Cygwin for this operation.

This fixes bug #963.

4 years agoRelax timing test because it's too tight for Windows.
Martin Ling [Fri, 24 Jan 2020 08:02:36 +0000 (08:02 +0000)]
Relax timing test because it's too tight for Windows.

On my test system, a delay of 1016ms was measured after a
sleep of 1000ms.

4 years agoREADME: update instructions for building with MSYS2.
Martin Ling [Fri, 24 Jan 2020 07:54:50 +0000 (07:54 +0000)]
README: update instructions for building with MSYS2.

4 years agoREADME: update build instructions with VS2019/MSBuild options.
Martin Ling [Fri, 24 Jan 2020 07:05:50 +0000 (07:05 +0000)]
README: update build instructions with VS2019/MSBuild options.

4 years agoAdd Visual Studio projects and solution to build example programs.
Martin Ling [Fri, 24 Jan 2020 05:59:29 +0000 (05:59 +0000)]
Add Visual Studio projects and solution to build example programs.

4 years agoFix use of variable length local array in await_events example.
Martin Ling [Fri, 24 Jan 2020 06:24:59 +0000 (06:24 +0000)]
Fix use of variable length local array in await_events example.

This prevented building with MSVC.

4 years agowindows: Fix another CreateFile usage.
Martin Ling [Fri, 24 Jan 2020 05:14:47 +0000 (05:14 +0000)]
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.

4 years agowindows: Fix a warning on size_t to USHORT conversion.
Martin Ling [Fri, 24 Jan 2020 05:06:55 +0000 (05:06 +0000)]
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.

4 years agowindows: Fix a warning on conversion to unsigned int.
Martin Ling [Fri, 24 Jan 2020 05:03:49 +0000 (05:03 +0000)]
windows: Fix a warning on conversion to unsigned int.

The result should be safe because we only use this function on time
differences as part of timeout calculations, not on absolute times.

Add an explicit cast to suppress the warning.

4 years agowindows: Fix warnings for conversions in time_as_timeval().
Martin Ling [Fri, 24 Jan 2020 04:55:32 +0000 (04:55 +0000)]
windows: Fix warnings for conversions in time_as_timeval().

Building with MSVC gave:

warning C4244: '=': conversion from 'LONGLONG' to 'long', possible loss of data

when assigning the results of these calculation to the long fields
of struct timeval. The result should be OK, but put an explicit
cast in to make the change clear and suppress the warning.

4 years agowindows: Avoid leak of write buffer on realloc failure.
Martin Ling [Fri, 24 Jan 2020 04:44:47 +0000 (04:44 +0000)]
windows: Avoid leak of write buffer on realloc failure.

VS2019 IntelliSense reported:

Warning C6308: 'realloc' might return null pointer: assigning null
               pointer to 'port->write_buf', which is passed as an
       argument to 'realloc', will cause the original memory
       block to be leaked.

This is correct, we would leak the buffer on a realloc failure.

Put the realloc result in a separate variable and handle the error
path before assigning the result to port->write_buf.

4 years agowindows: Use correct variant of FormatMessage.
Martin Ling [Fri, 24 Jan 2020 04:30:22 +0000 (04:30 +0000)]
windows: Use correct variant of FormatMessage.

When built with MSVC and unicode enabled, using 'message' gave:

warning C4133: 'initializing': incompatible types - from 'TCHAR *' to 'char *'

FormatMessage expands to either FormatMessageA or FormatMessageW
depending if unicode is enabled, and generates either a char (8-bit)
or WCHAR (UTF-16) string accordingly.

Since sp_last_error_message() returns char *, we must use the 8-bit
variant. The message will be encoded in the current code page.

4 years agowindows: Use correct variant of CreateFile.
Martin Ling [Fri, 24 Jan 2020 04:00:13 +0000 (04:00 +0000)]
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.

4 years agoFix some warnings for size_t, DWORD and int conversions.
Martin Ling [Fri, 24 Jan 2020 03:11:47 +0000 (03:11 +0000)]
Fix some warnings for size_t, DWORD and int conversions.

These cases are all in the sp_[non]blocking_{read,write} functions.

On MSVC, these conversions would generate warnings such as:
warning C4267: '=': conversion from 'size_t' to 'DWORD', possible loss of data

The warnings are genuine. There are some places where overflow is technically
possible, due to our use of size_t for sizes in function parameters (unsigned
64-bit on Windows x64), but an enum for return values (typically signed int
and 32-bit, but not guaranteed to be so by the standards), plus the Win32 API
usage of DWORD (unsigned 32-bit) for sizes in ReadFile/WriteFile.

However, overflow in practice would require reading/writing more than 2GB
over a serial port in a single call and is therefore unlikely to be a
real-world concern. I have therefore not tried to catch those cases - but the
places it is possible do now have explicit casts to the smaller types so that
they are more obvious.

We could document and test for a maximum read/write size of INT_MAX, but that
would still depend on the storage of 'enum sp_return' being at least a signed
int, which as I understand it the C standard does not require.

To be absolutely correct we would need a different API where sp_return
was only used for result codes, and the read/write functions took a
pointer to size_t for result sizes.

4 years agoReplace some usages of int with size_t to fix overflow warnings.
Martin Ling [Fri, 24 Jan 2020 03:01:23 +0000 (03:01 +0000)]
Replace some usages of int with size_t to fix overflow warnings.

On MSVC, these gave the following warning:

warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data

4 years agoAdd project files for Visual Studio 2019.
Martin Ling [Fri, 24 Jan 2020 02:56:50 +0000 (02:56 +0000)]
Add project files for Visual Studio 2019.

4 years agoAdjust headers and include ordering for MSVC support.
Martin Ling [Fri, 24 Jan 2020 02:56:05 +0000 (02:56 +0000)]
Adjust headers and include ordering for MSVC support.

4 years agoAdd example of waiting for events.
Martin Ling [Thu, 23 Jan 2020 02:54:23 +0000 (02:54 +0000)]
Add example of waiting for events.

4 years agoAdd an example of proper error handling.
Martin Ling [Mon, 20 Jan 2020 08:28:25 +0000 (08:28 +0000)]
Add an example of proper error handling.

4 years agoAdd some more narrative docs on the configuration API.
Martin Ling [Mon, 20 Jan 2020 07:40:10 +0000 (07:40 +0000)]
Add some more narrative docs on the configuration API.

4 years agoAdd example of how to configure a port.
Martin Ling [Mon, 20 Jan 2020 06:58:54 +0000 (06:58 +0000)]
Add example of how to configure a port.

4 years agoUse SP_API prefix for functions in libserialport.h.
Martin Ling [Mon, 20 Jan 2020 05:02:27 +0000 (05:02 +0000)]
Use SP_API prefix for functions in libserialport.h.

For MSVC, we need to set the __declspec() for public symbols to
dllexport or dllimport, depending if we are building or using the
library. So, detect MSVC and define SP_API appropriately if found.
We use the LIBSERIALPORT_MSBUILD define to distinguish between
building and using the library, which will need to be set in the
project configuration when building the library using MS tools.

For normal client use of the header on other systems, we need to
define SP_API to nothing to avoid it being undefined, but we need
to avoid doing this in the case where we are including the header
whilst building the library with autotools and SP_API is already
set by autoconf. So define LIBSERIALPORT_ATBUILD in AM_CFLAGS,
and don't touch SP_API in the header if that's set.

4 years agoUse a static header file, not dependent on autoconf.
Martin Ling [Mon, 20 Jan 2020 04:51:52 +0000 (04:51 +0000)]
Use a static header file, not dependent on autoconf.

4 years agowindows: wc_to_utf8: use some clearer variable names.
Martin Ling [Sun, 29 Dec 2019 16:15:08 +0000 (17:15 +0100)]
windows: wc_to_utf8: use some clearer variable names.

4 years agowindows: Don't try to include <unistd.h>.
Martin Ling [Sun, 29 Dec 2019 13:22:00 +0000 (14:22 +0100)]
windows: Don't try to include <unistd.h>.

This should enable compatibility with MSVC.

4 years agowindows: wc_to_utf8: Eliminate variable-length array.
Martin Ling [Sat, 28 Dec 2019 21:38:04 +0000 (22:38 +0100)]
windows: wc_to_utf8: Eliminate variable-length array.

This should enable compatibility with MSVC.

4 years agowindows: Use a fixed worst-case WRITEFILE_MAX_SIZE.
Martin Ling [Mon, 20 Jan 2020 02:01:38 +0000 (02:01 +0000)]
windows: Use a fixed worst-case WRITEFILE_MAX_SIZE.

This saves needing to include and isolate the DDK headers.

4 years agowindows: Handle the case where there are no serial ports at all.
Martin Ling [Mon, 20 Jan 2020 01:42:00 +0000 (01:42 +0000)]
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.

4 years agowindows: Handle registry lookup failures correctly.
Martin Ling [Mon, 20 Jan 2020 01:28:17 +0000 (01:28 +0000)]
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.

4 years agowindows: Loop over WriteFile() if write size exceeds limit.
Martin Ling [Sat, 4 Jan 2020 00:13:58 +0000 (00:13 +0000)]
windows: Loop over WriteFile() if write size exceeds limit.

Fixes #1469.

4 years agoAdd test program for timing functions.
Martin Ling [Mon, 20 Jan 2020 03:43:49 +0000 (03:43 +0000)]
Add test program for timing functions.

4 years agoMove timing routines to separate file.
Martin Ling [Sat, 4 Jan 2020 00:43:41 +0000 (00:43 +0000)]
Move timing routines to separate file.

4 years agoMove commonly used start flag into timeout helpers.
Martin Ling [Sat, 4 Jan 2020 00:33:50 +0000 (00:33 +0000)]
Move commonly used start flag into timeout helpers.

4 years agoMove special case for poll() timeout to call site.
Martin Ling [Sat, 4 Jan 2020 00:13:24 +0000 (00:13 +0000)]
Move special case for poll() timeout to call site.

4 years agoSupport timing helpers on Windows.
Martin Ling [Fri, 3 Jan 2020 23:50:31 +0000 (23:50 +0000)]
Support timing helpers on Windows.

4 years agoMore generic solution for limiting per-call timeout.
Martin Ling [Fri, 3 Jan 2020 23:33:48 +0000 (23:33 +0000)]
More generic solution for limiting per-call timeout.

4 years agoMove repetitive timeout code into helper functions.
Martin Ling [Fri, 3 Jan 2020 22:42:00 +0000 (22:42 +0000)]
Move repetitive timeout code into helper functions.

4 years agoAbstract all time handling operations.
Martin Ling [Sun, 23 Sep 2018 16:10:21 +0000 (17:10 +0100)]
Abstract all time handling operations.

4 years agoMakefile.am: Add example files to the tarball.
Uwe Hermann [Sun, 5 Jan 2020 17:19:00 +0000 (18:19 +0100)]
Makefile.am: Add example files to the tarball.

4 years agoDoxygen: Fix an issue causing missing #define documentation output.
Uwe Hermann [Sun, 5 Jan 2020 17:17:04 +0000 (18:17 +0100)]
Doxygen: Fix an issue causing missing #define documentation output.

  Searching for documented defines...
  [...]libserialport.h:1624: warning: documentation for unknown define SP_PACKAGE_VERSION_MAJOR found.
  [...]libserialport.h:1627: warning: documentation for unknown define SP_PACKAGE_VERSION_MINOR found.
  [...]libserialport.h:1630: warning: documentation for unknown define SP_PACKAGE_VERSION_MICRO found.
  [...]libserialport.h:1633: warning: documentation for unknown define SP_PACKAGE_VERSION_STRING found.
  [...]libserialport.h:1640: warning: documentation for unknown define SP_LIB_VERSION_CURRENT found.
  [...]libserialport.h:1643: warning: documentation for unknown define SP_LIB_VERSION_REVISION found.
  [...]libserialport.h:1646: warning: documentation for unknown define SP_LIB_VERSION_AGE found.
  [...]libserialport.h:1649: warning: documentation for unknown define SP_LIB_VERSION_STRING found.

4 years agoUpdate Doxyfile for doxygen 1.8.16.
Martin Ling [Sun, 5 Jan 2020 16:17:40 +0000 (16:17 +0000)]
Update Doxyfile for doxygen 1.8.16.

4 years agoRelease examples as public domain.
Martin Ling [Sun, 5 Jan 2020 14:53:09 +0000 (14:53 +0000)]
Release examples as public domain.

4 years agoAdd some additional formatting hints to Doxygen comments.
Martin Ling [Sun, 5 Jan 2020 03:28:58 +0000 (03:28 +0000)]
Add some additional formatting hints to Doxygen comments.

4 years agoIntegrate examples into Doxygen.
Martin Ling [Sun, 5 Jan 2020 03:04:38 +0000 (03:04 +0000)]
Integrate examples into Doxygen.

4 years agoAdd examples directory with two example programs.
Martin Ling [Sun, 5 Jan 2020 02:04:06 +0000 (02:04 +0000)]
Add examples directory with two example programs.

4 years agoandroid: Fix build compatibility with NDK platform 21 and up.
Martin Ling [Sat, 4 Jan 2020 23:00:17 +0000 (23:00 +0000)]
android: Fix build compatibility with NDK platform 21 and up.

In platforms 21 and higher of the NDK, linux/serial.h is available,
which it was not before. This broke the build, because the configure
script would detect the availability of 'struct serial_struct' in that
header and set HAVE_STRUCT_SERIAL_STRUCT, but the #ifndef __ANDROID__
in libserialport_internal.h stopped us actually including the header.

This change fixes things to build with all versions of the NDK, and is
tested with builds for arm from versions 9 to 24.

Version 21 also added availability of tcdrain(), so we also use that
where available, and only use the direct ioctl() method on NDK < 21.

Fixes #1078.

4 years agoDefine _POSIX_C_SOURCE to 199309L to get clock_gettime().
Martin Ling [Sat, 4 Jan 2020 15:39:54 +0000 (15:39 +0000)]
Define _POSIX_C_SOURCE to 199309L to get clock_gettime().

4 years agolinux: Fix compile warning on gcc 6+ for readlink() call.
Martin Ling [Tue, 31 Dec 2019 15:50:55 +0000 (16:50 +0100)]
linux: Fix compile warning on gcc 6+ for readlink() call.

Fixes #1268.

4 years agoUse O_CLOEXEC where available
Christian Seiler [Sun, 15 Oct 2017 17:28:05 +0000 (19:28 +0200)]
Use O_CLOEXEC where available

Ensures that the file descriptor is (by default) not passed to
subprocesses spawned by applications using libserialport.

This fixes bug #1051.

4 years agowindows: Fix a build error.
Uwe Hermann [Sat, 28 Dec 2019 22:39:15 +0000 (23:39 +0100)]
windows: Fix a build error.

  serialport.c: In function 'get_time':
  serialport.c:64:6: warning: implicit declaration of function 'clock_gettime' [-Wimplicit-function-declaration]
    if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1)
        ^
  serialport.c:64:20: error: 'CLOCK_MONOTONIC' undeclared (first use in this function)
    if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1)
                      ^
  serialport.c:64:20: note: each undeclared identifier is reported only once for each function it appears in
  serialport.c:65:17: error: 'CLOCK_REALTIME' undeclared (first use in this function)
     clock_gettime(CLOCK_REALTIME, &ts);
                   ^
  serialport.c: At top level:
  serialport.c:60:13: warning: 'get_time' defined but not used [-Wunused-function]
   static void get_time(struct timeval *time)
               ^

4 years agoFall back to CLOCK_REALTIME if CLOCK_MONOTONIC not usable.
Martin Ling [Sun, 23 Sep 2018 17:03:32 +0000 (18:03 +0100)]
Fall back to CLOCK_REALTIME if CLOCK_MONOTONIC not usable.

Sounds like this may be necessary on some older systems.

4 years agoUse mach_absolute_time() on OSX without clock_gettime().
Martin Ling [Sun, 23 Sep 2018 16:43:46 +0000 (17:43 +0100)]
Use mach_absolute_time() on OSX without clock_gettime().

This should fix #759 for OSX versions below 10.12.

4 years agoUse clock_gettime(CLOCK_MONOTONIC) if available.
Martin Ling [Sun, 23 Sep 2018 16:28:11 +0000 (17:28 +0100)]
Use clock_gettime(CLOCK_MONOTONIC) if available.

Should fix #759 except on OSX versions below 10.12, which don't
have clock_gettime.

4 years agoconfigure: Check whether clock_gettime is available.
Martin Ling [Sun, 23 Sep 2018 16:22:20 +0000 (17:22 +0100)]
configure: Check whether clock_gettime is available.

4 years agoMove all gettimeofday() calls into a wrapper function.
Martin Ling [Sun, 23 Sep 2018 16:19:50 +0000 (17:19 +0100)]
Move all gettimeofday() calls into a wrapper function.

4 years agowindows: Use architecture-specific size limit for WriteFile calls.
Martin Ling [Sat, 28 Dec 2019 18:47:06 +0000 (19:47 +0100)]
windows: Use architecture-specific size limit for WriteFile calls.

4 years agowindows: Use an adaptively sized buffer for nonblocking writes.
Martin Ling [Mon, 3 Jul 2017 20:43:38 +0000 (21:43 +0100)]
windows: Use an adaptively sized buffer for nonblocking writes.

4 years agowindows: Await completion of previous write before changing config.
Martin Ling [Mon, 3 Jul 2017 19:56:21 +0000 (20:56 +0100)]
windows: Await completion of previous write before changing config.

4 years agounix: Fix handling of EAGAIN in sp_nonblocking_write().
Martin Ling [Sat, 28 Dec 2019 16:53:11 +0000 (17:53 +0100)]
unix: Fix handling of EAGAIN in sp_nonblocking_write().

4 years agoRandom minor whitespace fixes.
Uwe Hermann [Sat, 28 Dec 2019 18:23:30 +0000 (19:23 +0100)]
Random minor whitespace fixes.

4 years agowindows: Fix incorrect wc_to_utf8() calls.
Uwe Hermann [Sat, 28 Dec 2019 16:08:49 +0000 (17:08 +0100)]
windows: Fix incorrect wc_to_utf8() calls.

This fixes bug #1079.

4 years agowindows: wc_to_utf8(): Fix a WCHAR related issue causing crashes.
Martin Jackson [Sat, 9 Sep 2017 22:37:48 +0000 (00:37 +0200)]
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.

6 years agoREADME: Add link to bug tracker.
Uwe Hermann [Sun, 17 Dec 2017 17:15:56 +0000 (18:15 +0100)]
README: Add link to bug tracker.

6 years agoREADME: Add missing contact info.
Uwe Hermann [Fri, 15 Dec 2017 17:38:11 +0000 (18:38 +0100)]
README: Add missing contact info.

6 years agowindows: Break out helper function for awaiting previous write completion.
Martin Ling [Mon, 3 Jul 2017 19:55:13 +0000 (20:55 +0100)]
windows: Break out helper function for awaiting previous write completion.

6 years agoRemove redundant inclusions of limits.h
Stefan Tauner [Sun, 21 May 2017 21:44:03 +0000 (23:44 +0200)]
Remove redundant inclusions of limits.h

The first one would be included for Windows too which seems to be
an error. The second one is obviously redundant.

6 years agoCanonicalize symlinks in portnames
Stefan Tauner [Sun, 21 May 2017 21:42:06 +0000 (23:42 +0200)]
Canonicalize symlinks in portnames

This allows users to supply symlinks created e.g. by udev rules instead
of the actual device names.

6 years agoFreeBSD: Add missing libusb-2.0 to pkg-config file.
Uwe Hermann [Wed, 13 Sep 2017 13:04:35 +0000 (15:04 +0200)]
FreeBSD: Add missing libusb-2.0 to pkg-config file.

This fixes bug #1033.

7 years agoLinux: fix for alpha where BOTHER is not defined.
Martin Ling [Sun, 19 Mar 2017 12:16:49 +0000 (12:16 +0000)]
Linux: fix for alpha where BOTHER is not defined.

Fixes bug #363.

7 years agoconfigure summary: Show compiler version and flags.
Uwe Hermann [Sun, 5 Mar 2017 16:01:17 +0000 (17:01 +0100)]
configure summary: Show compiler version and flags.

7 years agoconfigure summary: Show whether shared/static build is enabled.
Uwe Hermann [Sun, 5 Mar 2017 15:43:58 +0000 (16:43 +0100)]
configure summary: Show whether shared/static build is enabled.

7 years agoconfigure summary: Slightly change formatting.
Uwe Hermann [Sun, 5 Mar 2017 15:42:37 +0000 (16:42 +0100)]
configure summary: Slightly change formatting.

7 years agouse readdir() instead of the deprecated readir_r()
Aurelien Jacobs [Fri, 14 Oct 2016 21:50:08 +0000 (23:50 +0200)]
use readdir() instead of the deprecated readir_r()

readir() is threadsafe on both linux and freebsd anyway.
The rationale behind the readdir_r() deprecation is in the glibc manual:
https://www.gnu.org/software/libc/manual/html_node/Reading_002fClosing-Directory.html

This fixes the following warning with recent glibc:

linux.c: In function ‘list_ports’:
linux.c:197:2: warning: ‘readdir_r’ is deprecated [-Wdeprecated-declarations]
  while (!readdir_r(dir, &entry, &result) && result) {
  ^~~~~

7 years agolibserialport: Fix Linux files not compiled in with a toolchain for ucLinux
Paul Cercueil [Mon, 29 Aug 2016 13:05:20 +0000 (15:05 +0200)]
libserialport: Fix Linux files not compiled in with a toolchain for ucLinux

Buildroot can create toolchains for the no-MMU flavour of Linux, with a triple
containing 'uclinux' instead of just 'linux'.

Signed-off-by: Paul Cercueil <redacted>
8 years agolinux: freebsd: do check on proper pointer libserialport-unreleased
Wolfram Sang [Fri, 19 Feb 2016 21:25:00 +0000 (22:25 +0100)]
linux: freebsd: do check on proper pointer

We want to check here if we added something to the list, not if the
function argument was valid. Problem spotted by Coverity, CID 50754.

Signed-off-by: Wolfram Sang <redacted>
8 years agoBump libtool version (not package version) to 1:0:1.
Uwe Hermann [Sat, 9 Jan 2016 00:13:45 +0000 (01:13 +0100)]
Bump libtool version (not package version) to 1:0:1.

The last release (0.1.0) had the libtool version (current:revision:age)
set to 0:0:0. Since this release doesn't change/remove any
interfaces (it does *add* new interfaces, though), 'current' and 'age'
are increased and 'revision' is set to 0, resulting in 1:0:1.

http://www.gnu.org/software/libtool/manual/libtool.html#Updating-version-info

Programs using libserialport don't need to be recompiled or relinked.

8 years agoNEWS: Last updates for the upcoming 0.1.1 release.
Uwe Hermann [Fri, 8 Jan 2016 23:48:39 +0000 (00:48 +0100)]
NEWS: Last updates for the upcoming 0.1.1 release.

8 years agoFix ERROR_SEM_TIMEOUT issue on Windows.
Uwe Hermann [Wed, 27 Jan 2016 07:19:38 +0000 (08:19 +0100)]
Fix ERROR_SEM_TIMEOUT issue on Windows.

The sp_blocking_write() call was incorrectly returning an error upon
ERROR_SEM_TIMEOUT. It now returns 0 instead.

8 years agoFix sp_blocking_read_next() implementation on Windows.
Uwe Hermann [Fri, 22 Jan 2016 14:30:44 +0000 (15:30 +0100)]
Fix sp_blocking_read_next() implementation on Windows.

A ReadFile() call needed to check the actual number of bytes read,
instead of assuming all requested bytes were read.