mirror of
git://sigrok.org/libserialport
synced 2023-08-10 21:13:24 +03:00
Make sure OS handles are set correctly for unopened / closed ports.
This commit is contained in:
parent
c6754b4517
commit
8f471c669f
@ -121,6 +121,12 @@ int sp_get_port_by_name(const char *portname, struct sp_port **port_ptr)
|
|||||||
|
|
||||||
memcpy(port->name, portname, len);
|
memcpy(port->name, portname, len);
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
port->hdl = INVALID_HANDLE_VALUE;
|
||||||
|
#else
|
||||||
|
port->fd = -1;
|
||||||
|
#endif
|
||||||
|
|
||||||
*port_ptr = port;
|
*port_ptr = port;
|
||||||
|
|
||||||
return SP_OK;
|
return SP_OK;
|
||||||
@ -491,10 +497,12 @@ int sp_close(struct sp_port *port)
|
|||||||
/* Returns non-zero upon success, 0 upon failure. */
|
/* Returns non-zero upon success, 0 upon failure. */
|
||||||
if (CloseHandle(port->hdl) == 0)
|
if (CloseHandle(port->hdl) == 0)
|
||||||
return SP_ERR_FAIL;
|
return SP_ERR_FAIL;
|
||||||
|
port->hdl = INVALID_HANDLE_VALUE;
|
||||||
#else
|
#else
|
||||||
/* Returns 0 upon success, -1 upon failure. */
|
/* Returns 0 upon success, -1 upon failure. */
|
||||||
if (close(port->fd) == -1)
|
if (close(port->fd) == -1)
|
||||||
return SP_ERR_FAIL;
|
return SP_ERR_FAIL;
|
||||||
|
port->fd = -1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return SP_OK;
|
return SP_OK;
|
||||||
|
Loading…
Reference in New Issue
Block a user